Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions src/absil/ilwritepdb.fs
Original file line number Diff line number Diff line change
Expand Up @@ -369,36 +369,63 @@ let generatePortablePdb (embedAllSource: bool) (embedSourceList: string list) (s
builder.WriteCompressedInteger( 0 )
builder.WriteCompressedInteger( MetadataTokens.GetRowNumber(DocumentHandle.op_Implicit(getDocumentHandle (sps.[i].Document))) )
else
//=============================================================================================================================================
// Sequence-point-record
let offsetDelta =
if i > 0 then sps.[i].Offset - sps.[i - 1].Offset // delta from previous offset
else sps.[i].Offset // delta IL offset

if i < 1 || offsetDelta <> 0 then // ILOffset must not be 0
// Validate these with magic numbers according to the portable pdb spec Sequence point dexcription:
// https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/specs/PortablePdb-Metadata.md#methoddebuginformation-table-0x31
//
// So the spec is actually bit iffy!!!!! (More like guidelines really. )
// It uses code similar to this to validate the values
// if (result < 0 || result >= ushort.MaxValue) // be errorfull
// Spec Says 0x10000 and value max = 0xFFFF but it can't even be = to maxvalue, and so the range is 0 .. 0xfffe inclusive
//=============================================================================================================================================

let capValue v maxValue =
if v < 0 then 0
elif v > maxValue then maxValue
else v

let capOffset v = capValue v 0xfffe
let capLine v = capValue v 0x1ffffffe
let capColumn v = capValue v 0xfffe

let offset = capOffset sps.[i].Offset
let startLine = capLine sps.[i].Line
let endLine = capLine sps.[i].EndLine
let startColumn = capColumn sps.[i].Column
let endColumn = capColumn sps.[i].EndColumn

let offsetDelta = // delta from previous offset
if i > 0 then offset - capOffset sps.[i - 1].Offset
else offset

if i < 1 || offsetDelta > 0 then
builder.WriteCompressedInteger(offsetDelta)

if sps.[i].Line = 0xfeefee && sps.[i].EndLine = 0xfeefee then // Hidden-sequence-point-record
// Hidden-sequence-point-record
if startLine = 0xfeefee || endLine = 0xfeefee || (startColumn = 0 && endColumn = 0)
then
builder.WriteCompressedInteger(0)
builder.WriteCompressedInteger(0)
else // Non-hidden-sequence-point-record
let deltaLines = sps.[i].EndLine - sps.[i].Line // lines
let deltaLines = endLine - startLine // lines
builder.WriteCompressedInteger(deltaLines)

let deltaColumns = sps.[i].EndColumn - sps.[i].Column // Columns
let deltaColumns = endColumn - startColumn // Columns
if deltaLines = 0 then
builder.WriteCompressedInteger(deltaColumns)
else
builder.WriteCompressedSignedInteger(deltaColumns)

if previousNonHiddenStartLine < 0 then // delta Start Line & Column:
builder.WriteCompressedInteger(sps.[i].Line)
builder.WriteCompressedInteger(sps.[i].Column)
builder.WriteCompressedInteger(startLine)
builder.WriteCompressedInteger(startColumn)
else
builder.WriteCompressedSignedInteger(sps.[i].Line - previousNonHiddenStartLine)
builder.WriteCompressedSignedInteger(sps.[i].Column - previousNonHiddenStartColumn)
builder.WriteCompressedSignedInteger(startLine - previousNonHiddenStartLine)
builder.WriteCompressedSignedInteger(startColumn - previousNonHiddenStartColumn)

previousNonHiddenStartLine <- sps.[i].Line
previousNonHiddenStartColumn <- sps.[i].Column
previousNonHiddenStartLine <- startLine
previousNonHiddenStartColumn <- startColumn

getDocumentHandle singleDocumentIndex, metadata.GetOrAddBlob(builder)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
<OtherFlags>$(OtherFlags) --warnon:1182 --maxerrors:20 --extraoptimizationloops:1</OtherFlags>
<UseAssetTargetFallback>true</UseAssetTargetFallback>
<Tailcalls>true</Tailcalls> <!-- .tail annotations always emitted for this binary, even in debug mode -->
<SkipPDBConversion>true</SkipPDBConversion>
<NGenBinary>true</NGenBinary>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net46' AND '$(OS)' == 'Windows_NT'">
<!-- portable PDBs can't be properly generated for this assembly, see https://github.com/Microsoft/visualfsharp/issues/5976 -->
<DebugType>full</DebugType>
<EnableSourceLink>false</EnableSourceLink>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.StartsWith('netstandard')) AND '$(OS)' == 'Windows_NT'">
Expand Down
5 changes: 4 additions & 1 deletion src/fsharp/ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,10 @@ and
/// Get the syntactic range of source code covered by this construct.
member e.Range =
match e with
| SynExpr.Paren (range=m)
| SynExpr.Paren (_, leftParenRange, rightParenRange, r) ->
match rightParenRange with
| Some rightParenRange when leftParenRange.FileIndex <> rightParenRange.FileIndex -> leftParenRange
| _ -> r
| SynExpr.Quote (range=m)
| SynExpr.Const (range=m)
| SynExpr.Typed (range=m)
Expand Down
49 changes: 30 additions & 19 deletions src/utils/prim-parsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -361,38 +361,49 @@ module internal Implementation =
#if DEBUG
if Flags.debug then Console.Write("reduce popping {0} values/states, lookahead {1}", n, report haveLookahead lookaheadToken)
#endif
for i = 0 to n - 1 do
// For every range to reduce merge it
for i = 0 to n - 1 do
if valueStack.IsEmpty then failwith "empty symbol stack"
let topVal = valueStack.Peep()
let topVal = valueStack.Peep() // Grab topVal
valueStack.Pop()
stateStack.Pop()
ruleValues.[(n-i)-1] <- topVal.value
ruleStartPoss.[(n-i)-1] <- topVal.startPos
ruleEndPoss.[(n-i)-1] <- topVal.endPos
if i = 0 then lhsPos.[1] <- topVal.endPos
if i = n - 1 then lhsPos.[0] <- topVal.startPos

// Use the lookahead token to populate the locations if the rhs is empty
if n = 0 then

let ruleIndex = (n-i)-1
ruleValues.[ruleIndex] <- topVal.value
ruleStartPoss.[ruleIndex] <- topVal.startPos
ruleEndPoss.[ruleIndex] <- topVal.endPos

if i = 0 then
// Initial range
lhsPos.[0] <- topVal.startPos
lhsPos.[1] <- topVal.endPos
elif topVal.startPos.FileIndex = lhsPos.[1].FileIndex && topVal.startPos.Line <= lhsPos.[1].Line then
// Reduce range if same file as the initial end point
lhsPos.[0] <- topVal.startPos

// Use the lookahead token to populate the locations if the rhs is empty
if n = 0 then
if haveLookahead then
lhsPos.[0] <- lookaheadStartPos
lhsPos.[1] <- lookaheadEndPos
lhsPos.[0] <- lookaheadStartPos
lhsPos.[1] <- lookaheadEndPos
else
lhsPos.[0] <- lexbuf.StartPos
lhsPos.[1] <- lexbuf.EndPos
try
// printf "reduce %d\n" prod
let redResult = reduction parseState
valueStack.Push(ValueInfo(redResult, lhsPos.[0], lhsPos.[1]))
try
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff could be made minimal, though it's no big deal, the other changes are an improvement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but my OCD doesn't work that way :-(

// printf "reduce %d\n" prod
let redResult = reduction parseState
let valueInfo = ValueInfo(redResult, lhsPos.[0], lhsPos.[1])
valueStack.Push(valueInfo)
let currState = stateStack.Peep()
let newGotoState = gotoTable.Read(int tables.productionToNonTerminalTable.[prod], currState)
stateStack.Push(newGotoState)

#if DEBUG
if Flags.debug then Console.WriteLine(" goto state {0}", newGotoState)
#endif
with
| Accept res ->
finished <- true
with
| Accept res ->
finished <- true
valueStack.Push(ValueInfo(res, lhsPos.[0], lhsPos.[1]))
| RecoverableParseError ->
#if DEBUG
Expand Down