Skip to content

Commit bde69ea

Browse files
authored
Merge pull request #1300 from dsyme/fix-105
Fix 105 - sequence points when "let rec" is used, plus other debug stepping issues
2 parents a8b607c + bc5c901 commit bde69ea

File tree

121 files changed

+4231
-9891
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+4231
-9891
lines changed

src/absil/il.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,8 +2982,14 @@ let mdef_code2code f md =
29822982
let prependInstrsToCode (instrs: ILInstr list) (c2: ILCode) =
29832983
let instrs = Array.ofList instrs
29842984
let n = instrs.Length
2985-
{ c2 with Labels = Dictionary.ofList [ for kvp in c2.Labels -> (kvp.Key, kvp.Value + n) ]
2986-
Instrs = Array.append instrs c2.Instrs }
2985+
match c2.Instrs.[0] with
2986+
// If there is a sequence point as the first instruction then keep it at the front
2987+
| I_seqpoint _ as i0 ->
2988+
{ c2 with Labels = Dictionary.ofList [ for kvp in c2.Labels -> (kvp.Key, if kvp.Value = 0 then 0 else kvp.Value + n) ]
2989+
Instrs = Array.append [| i0 |] (Array.append instrs c2.Instrs.[1..]) }
2990+
| _ ->
2991+
{ c2 with Labels = Dictionary.ofList [ for kvp in c2.Labels -> (kvp.Key, kvp.Value + n) ]
2992+
Instrs = Array.append instrs c2.Instrs }
29872993

29882994
let prependInstrsToMethod new_code md =
29892995
mdef_code2code (prependInstrsToCode new_code) md

src/absil/ilx.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ type IlxClosureSpec =
120120
type IlxClosureInfo =
121121
{ cloStructure: IlxClosureLambdas
122122
cloFreeVars: IlxClosureFreeVar[]
123-
cloCode: Lazy<ILMethodBody>
124-
cloSource: ILSourceMarker option}
123+
cloCode: Lazy<ILMethodBody> }
125124

126125
type IlxUnionInfo =
127126
{ /// is the representation public?

src/absil/ilx.fsi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ type IlxClosureApps =
9797
type IlxClosureInfo =
9898
{ cloStructure: IlxClosureLambdas
9999
cloFreeVars: IlxClosureFreeVar[]
100-
cloCode: Lazy<ILMethodBody>
101-
cloSource: ILSourceMarker option}
100+
cloCode: Lazy<ILMethodBody> }
102101

103102
type IlxUnionInfo =
104103
{ /// Is the representation public?

src/fsharp/IlxGen.fs

Lines changed: 142 additions & 91 deletions
Large diffs are not rendered by default.

src/ilx/EraseClosures.fs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ let isSupportedDirectCall apps =
116116
// --------------------------------------------------------------------
117117

118118
let mkFuncTypeRef n =
119-
if n = 1 then mkILTyRef (IlxSettings.ilxFsharpCoreLibScopeRef (),IlxSettings.ilxNamespace () ^ ".FSharpFunc`2")
119+
if n = 1 then mkILTyRef (IlxSettings.ilxFsharpCoreLibScopeRef (),IlxSettings.ilxNamespace () + ".FSharpFunc`2")
120120
else mkILNestedTyRef (IlxSettings.ilxFsharpCoreLibScopeRef (),
121-
[IlxSettings.ilxNamespace () ^ ".OptimizedClosures"],
122-
"FSharpFunc`"^ string (n + 1))
121+
[IlxSettings.ilxNamespace () + ".OptimizedClosures"],
122+
"FSharpFunc`"+ string (n + 1))
123123
type cenv =
124124
{ ilg:ILGlobals;
125125
tref_Func: ILTypeRef[];
@@ -128,7 +128,7 @@ type cenv =
128128
let newIlxPubCloEnv(ilg) =
129129
{ ilg=ilg;
130130
tref_Func= Array.init 10 (fun i -> mkFuncTypeRef(i+1));
131-
mkILTyFuncTy=ILType.Boxed (mkILNonGenericTySpec (mkILTyRef (IlxSettings.ilxFsharpCoreLibScopeRef (), IlxSettings.ilxNamespace () ^ ".FSharpTypeFunc"))) }
131+
mkILTyFuncTy=ILType.Boxed (mkILNonGenericTySpec (mkILTyRef (IlxSettings.ilxFsharpCoreLibScopeRef (), IlxSettings.ilxNamespace () + ".FSharpTypeFunc"))) }
132132

133133
let mkILTyFuncTy cenv = cenv.mkILTyFuncTy
134134

@@ -354,7 +354,6 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
354354
let nowTy = mkILFormalBoxedTy nowTypeRef td.GenericParams
355355
let nowCloRef = IlxClosureRef(nowTypeRef,clo.cloStructure,nowFields)
356356
let nowCloSpec = mkILFormalCloRef td.GenericParams nowCloRef
357-
let tagClo = clo.cloSource
358357
let tagApp = (Lazy.force clo.cloCode).SourceMarker
359358

360359
let tyargsl,tmargsl,laterStruct = stripSupportedAbstraction clo.cloStructure
@@ -416,10 +415,10 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
416415
if (match laterStruct with Lambdas_return _ -> false | _ -> true) then
417416

418417
let nowStruct = List.foldBack (fun x y -> Lambdas_forall(x,y)) tyargsl (Lambdas_return nowReturnTy)
419-
let laterTypeName = td.Name^"T"
418+
let laterTypeName = td.Name+"T"
420419
let laterTypeRef = mkILNestedTyRef (ILScopeRef.Local,encl,laterTypeName)
421420
let laterGenericParams = td.GenericParams @ addedGenParams
422-
let selfFreeVar = mkILFreeVar(CompilerGeneratedName ("self"^string nowFields.Length),true,nowCloSpec.ILType)
421+
let selfFreeVar = mkILFreeVar(CompilerGeneratedName ("self"+string nowFields.Length),true,nowCloSpec.ILType)
423422
let laterFields = Array.append nowFields [| selfFreeVar |]
424423
let laterCloRef = IlxClosureRef(laterTypeRef,laterStruct,laterFields)
425424
let laterCloSpec = mkILFormalCloRef laterGenericParams laterCloRef
@@ -434,8 +433,6 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
434433
cloFreeVars=laterFields;
435434
cloCode=notlazy laterCode}
436435

437-
let laterTypeDefs = laterTypeDefs |> List.map (addMethodGeneratedAttrsToTypeDef cenv.ilg)
438-
439436
// This is the code which will get called when then "now"
440437
// arguments get applied. Convert it with the information
441438
// that it is the code for a closure...
@@ -456,6 +453,9 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
456453
let nowTypeDefs =
457454
convIlxClosureDef cenv encl td {clo with cloStructure=nowStruct;
458455
cloCode=notlazy nowCode}
456+
457+
let nowTypeDefs = nowTypeDefs |> List.map (addMethodGeneratedAttrsToTypeDef cenv.ilg)
458+
459459
nowTypeDefs @ laterTypeDefs
460460
else
461461
// CASE 1b. Build a type application.
@@ -470,11 +470,12 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
470470
MethodBody.IL (convILMethodBody (Some nowCloSpec,boxReturnTy) (Lazy.force clo.cloCode)))
471471
let ctorMethodDef =
472472
mkILStorageCtor
473-
(tagClo,
473+
(None,
474474
[ mkLdarg0; mkNormalCall (mkILCtorMethSpecForTy (cenv.mkILTyFuncTy, [])) ],
475475
nowTy,
476476
mkILCloFldSpecs cenv nowFields,
477477
ILMemberAccess.Assembly)
478+
|> addMethodGeneratedAttrs cenv.ilg
478479

479480
let cloTypeDef =
480481
{ Name = td.Name;
@@ -509,7 +510,7 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
509510
// CASE 2a - Too Many Term Arguments or Remaining Type arguments - Split the Closure Class in Two
510511
if (match laterStruct with Lambdas_return _ -> false | _ -> true) then
511512
let nowStruct = List.foldBack (fun l r -> Lambdas_lambda(l,r)) nowParams (Lambdas_return nowReturnTy)
512-
let laterTypeName = td.Name^"D"
513+
let laterTypeName = td.Name+"D"
513514
let laterTypeRef = mkILNestedTyRef (ILScopeRef.Local,encl,laterTypeName)
514515
let laterGenericParams = td.GenericParams
515516
// Number each argument left-to-right, adding one to account for the "this" pointer
@@ -534,10 +535,13 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
534535
[ I_newobj (laterCloSpec.Constructor, None) ]
535536
end,
536537
tagApp)
538+
537539
let nowTypeDefs =
538540
convIlxClosureDef cenv encl td {clo with cloStructure=nowStruct;
539541
cloCode=notlazy nowCode}
542+
540543
let laterCode = rewriteCodeToAccessArgsFromEnv laterCloSpec argToFreeVarMap
544+
541545
let laterTypeDefs =
542546
convIlxClosureDef cenv encl
543547
{td with GenericParams=laterGenericParams;
@@ -546,29 +550,35 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
546550
{clo with cloStructure=laterStruct;
547551
cloFreeVars=laterFields;
548552
cloCode=notlazy laterCode}
553+
549554
// add 'compiler generated' to all the methods in the 'now' classes
550-
let laterTypeDefs = laterTypeDefs |> List.map (addMethodGeneratedAttrsToTypeDef cenv.ilg)
555+
let nowTypeDefs = nowTypeDefs |> List.map (addMethodGeneratedAttrsToTypeDef cenv.ilg)
556+
551557
nowTypeDefs @ laterTypeDefs
552558

553559
else
554560
// CASE 2b - Build an Term Application Apply method
555561
// CASE 2b2. Build a term application as a virtual method.
556562

557563
let nowEnvParentClass = typ_Func cenv (typesOfILParamsList nowParams) nowReturnTy
564+
558565
let cloTypeDef =
559566
let nowApplyMethDef =
560567
mkILNonGenericVirtualMethod
561568
("Invoke",ILMemberAccess.Public,
562569
nowParams,
563570
mkILReturn nowReturnTy,
564571
MethodBody.IL (convILMethodBody (Some nowCloSpec,None) (Lazy.force clo.cloCode)))
572+
565573
let ctorMethodDef =
566574
mkILStorageCtor
567-
(tagClo,
575+
(None,
568576
[ mkLdarg0; mkNormalCall (mkILCtorMethSpecForTy (nowEnvParentClass,[])) ],
569577
nowTy,
570578
mkILCloFldSpecs cenv nowFields,
571579
ILMemberAccess.Assembly)
580+
|> addMethodGeneratedAttrs cenv.ilg
581+
572582
{ Name = td.Name;
573583
GenericParams= td.GenericParams;
574584
Access = td.Access;
@@ -592,12 +602,15 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
592602
HasSecurity=false;
593603
SecurityDecls=emptyILSecurityDecls;
594604
tdKind = ILTypeDefKind.Class; }
605+
595606
[cloTypeDef]
596-
| [],[ ],Lambdas_return _ ->
607+
608+
| [],[],Lambdas_return _ ->
609+
597610
// No code is being declared: just bake a (mutable) environment
598611
let cloCode' =
599612
match td.Extends with
600-
| None -> (mkILNonGenericEmptyCtor tagClo cenv.ilg.typ_Object).MethodBody
613+
| None -> (mkILNonGenericEmptyCtor None cenv.ilg.typ_Object).MethodBody
601614
| Some _ -> convILMethodBody (Some nowCloSpec,None) (Lazy.force clo.cloCode)
602615

603616
let ctorMethodDef =
@@ -615,7 +628,7 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
615628
mkNormalStfld (mkILFieldSpecInTy (nowTy,nm,ty));
616629
]) flds))
617630
cloCode'.Code,
618-
tagClo))
631+
None))
619632

620633
let cloTypeDef =
621634
{ td with
@@ -626,9 +639,11 @@ let rec convIlxClosureDef cenv encl (td: ILTypeDef) clo =
626639
Methods= mkILMethods (ctorMethodDef :: List.map (convMethodDef (Some nowCloSpec)) td.Methods.AsList);
627640
Fields= mkILFields (mkILCloFldDefs cenv nowFields @ td.Fields.AsList);
628641
tdKind = ILTypeDefKind.Class; }
642+
629643
[cloTypeDef]
644+
630645
| a,b,_ ->
631-
failwith ("Unexpected unsupported abstraction sequence, #tyabs = "^string a.Length ^ ", #tmabs = "^string b.Length)
646+
failwith ("Unexpected unsupported abstraction sequence, #tyabs = "+string a.Length + ", #tmabs = "+string b.Length)
632647

633648
newTypeDefs
634649

src/ilx/EraseUnions.fs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,24 +397,26 @@ let genWith g : ILCode =
397397
Locals = [] }
398398

399399

400-
let mkBrIsNotData ilg (avoidHelpers, cuspec,cidx,tg) =
400+
let mkBrIsData ilg sense (avoidHelpers, cuspec,cidx,tg) =
401+
let neg = (if sense then BI_brfalse else BI_brtrue)
402+
let pos = (if sense then BI_brtrue else BI_brfalse)
401403
let alt = altOfUnionSpec cuspec cidx
402404
let altTy = tyForAlt cuspec alt
403405
let altName = alt.Name
404406
if cuspecRepr.RepresentAlternativeAsNull (cuspec,alt) then
405-
[ I_brcmp (BI_brtrue,tg) ]
407+
[ I_brcmp (neg,tg) ]
406408
elif cuspecRepr.RepresentSingleNonNullaryAlternativeAsInstancesOfRootClassAndAnyOtherAlternativesAsNull (cuspec,alt) then
407409
// in this case we can use a null test
408-
[ I_brcmp (BI_brfalse,tg) ]
410+
[ I_brcmp (pos,tg) ]
409411
else
410412
match cuspecRepr.DiscriminationTechnique cuspec with
411413
| SingleCase -> [ ]
412-
| RuntimeTypes -> mkRuntimeTypeDiscriminateThen ilg avoidHelpers cuspec alt altName altTy (I_brcmp (BI_brfalse,tg))
413-
| IntegerTag -> mkTagDiscriminateThen ilg cuspec cidx (I_brcmp (BI_brfalse,tg))
414+
| RuntimeTypes -> mkRuntimeTypeDiscriminateThen ilg avoidHelpers cuspec alt altName altTy (I_brcmp (pos,tg))
415+
| IntegerTag -> mkTagDiscriminateThen ilg cuspec cidx (I_brcmp (pos,tg))
414416
| TailOrNull ->
415417
match cidx with
416-
| TagNil -> mkGetTailOrNull avoidHelpers cuspec @ [I_brcmp (BI_brtrue,tg)]
417-
| TagCons -> mkGetTailOrNull avoidHelpers cuspec @ [ I_brcmp (BI_brfalse,tg)]
418+
| TagNil -> mkGetTailOrNull avoidHelpers cuspec @ [I_brcmp (neg,tg)]
419+
| TagCons -> mkGetTailOrNull avoidHelpers cuspec @ [ I_brcmp (pos,tg)]
418420
| _ -> failwith "unexpected"
419421

420422

src/ilx/EraseUnions.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ val mkLdDataAddr : bool * IlxUnionSpec * int * int -> ILInstr list
2525
val mkStData : IlxUnionSpec * int * int -> ILInstr list
2626

2727
/// Make the instruction sequence for a "brisnotdata" operation
28-
val mkBrIsNotData : ILGlobals -> avoidHelpers:bool * IlxUnionSpec * int * ILCodeLabel -> ILInstr list
28+
val mkBrIsData : ILGlobals -> sense: bool -> avoidHelpers:bool * IlxUnionSpec * int * ILCodeLabel -> ILInstr list
2929

3030
/// Make the type definition for a union type
3131
val mkClassUnionDef : ILGlobals -> ILTypeRef -> ILTypeDef -> IlxUnionInfo -> ILTypeDef

0 commit comments

Comments
 (0)