Skip to content

Commit 7f037b7

Browse files
authored
Optimize attribute checking (#16036)
* Optimize attribute checking
1 parent 7a8ef38 commit 7f037b7

File tree

4 files changed

+5
-14
lines changed

4 files changed

+5
-14
lines changed

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10788,6 +10788,7 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn
1078810788
let mAttr = synAttr.Range
1078910789
let typath, tyid = List.frontAndBack tycon
1079010790
let tpenv = emptyUnscopedTyparEnv
10791+
let ad = env.eAccessRights
1079110792

1079210793
// if we're checking an attribute that was applied directly to a getter or a setter, then
1079310794
// what we're really checking against is a method, not a property
@@ -10796,13 +10797,12 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn
1079610797
let try1 n =
1079710798
let tyid = mkSynId tyid.idRange n
1079810799
let tycon = (typath @ [tyid])
10799-
let ad = env.eAccessRights
10800+
1080010801
match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.UseInAttribute OpenQualified env.eNameResEnv ad tycon TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No with
1080110802
| Exception err -> raze err
10802-
| _ -> success(TcTypeAndRecover cenv NoNewTypars CheckCxs ItemOccurence.UseInAttribute WarnOnIWSAM.Yes env tpenv (SynType.App(SynType.LongIdent(SynLongIdent(tycon, [], List.replicate tycon.Length None)), None, [], [], None, false, mAttr)) )
10803-
ForceRaise ((try1 (tyid.idText + "Attribute")) |> otherwise (fun () -> (try1 tyid.idText)))
10803+
| Result(tinstEnclosing, tcref) -> success(TcTypeApp cenv NoNewTypars CheckCxs ItemOccurence.UseInAttribute env tpenv mAttr tcref tinstEnclosing [])
1080410804

10805-
let ad = env.eAccessRights
10805+
ForceRaise ((try1 (tyid.idText + "Attribute")) |> otherwise (fun () -> (try1 tyid.idText)))
1080610806

1080710807
if not (IsTypeAccessible g cenv.amap mAttr ad ty) then errorR(Error(FSComp.SR.tcTypeIsInaccessible(), mAttr))
1080810808

tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,4 @@ let GetAllUsesOfAllSymbols() =
165165
traceProvider.ForceFlush() |> ignore
166166
traceProvider.Dispose()
167167

168-
Assert.Equal(80, result.Length)
168+
Assert.Equal(79, result.Length)

tests/service/EditorTests.fs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ type Class1() =
781781
su.Symbol.ToString(), (r.StartLine, r.StartColumn, r.EndLine, r.EndColumn))
782782
|> shouldEqual
783783
[|("LiteralAttribute", (3, 10, 3, 17))
784-
("LiteralAttribute", (3, 10, 3, 17))
785784
("member .ctor", (3, 10, 3, 17))
786785
("val ModuleValue", (3, 20, 3, 31))
787786
("val op_Addition", (6, 26, 6, 27))
@@ -793,11 +792,9 @@ type Class1() =
793792
("Class1", (10, 5, 10, 11))
794793
("member .ctor", (10, 5, 10, 11))
795794
("LiteralAttribute", (11, 10, 11, 17))
796-
("LiteralAttribute", (11, 10, 11, 17))
797795
("member .ctor", (11, 10, 11, 17))
798796
("val ClassValue", (11, 20, 11, 30))
799797
("LiteralAttribute", (12, 17, 12, 24))
800-
("LiteralAttribute", (12, 17, 12, 24))
801798
("member .ctor", (12, 17, 12, 24))
802799
("val StaticClassValue", (12, 27, 12, 43))
803800
("val ClassValue", (14, 12, 14, 22))

tests/service/ProjectAnalysisTests.fs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,6 @@ let ``Test Project14 all symbols`` () =
23492349
allUsesOfAllSymbols |> shouldEqual
23502350
[|("StructAttribute", "StructAttribute", "file1", ((4, 2), (4, 8)),
23512351
["attribute"]);
2352-
("StructAttribute", "StructAttribute", "file1", ((4, 2), (4, 8)), ["type"]);
23532352
("member .ctor", "StructAttribute", "file1", ((4, 2), (4, 8)), []);
23542353
("int", "int", "file1", ((5, 9), (5, 12)), ["type"]);
23552354
("int", "int", "file1", ((5, 9), (5, 12)), ["type"]);
@@ -2504,14 +2503,10 @@ let ``Test Project16 all symbols`` () =
25042503
allUsesOfAllSymbols |> shouldEqual
25052504
[|("ClassAttribute", "ClassAttribute", "sig1", ((8, 6), (8, 11)),
25062505
["attribute"], ["class"]);
2507-
("ClassAttribute", "ClassAttribute", "sig1", ((8, 6), (8, 11)), ["type"],
2508-
["class"]);
25092506
("member .ctor", "ClassAttribute", "sig1", ((8, 6), (8, 11)), [],
25102507
["member"]);
25112508
("ClassAttribute", "ClassAttribute", "sig1", ((12, 6), (12, 11)),
25122509
["attribute"], ["class"]);
2513-
("ClassAttribute", "ClassAttribute", "sig1", ((12, 6), (12, 11)), ["type"],
2514-
["class"]);
25152510
("member .ctor", "ClassAttribute", "sig1", ((12, 6), (12, 11)), [],
25162511
["member"]);
25172512
("int", "int", "sig1", ((16, 19), (16, 22)), ["type"], ["abbrev"]);
@@ -5085,7 +5080,6 @@ let ``Test Project40 all symbols`` () =
50855080
("IsNone", ((4, 33), (4, 41)), ["member"; "prop"; "funky"]);
50865081
("f", ((4, 4), (4, 5)), ["val"]);
50875082
("CompilationRepresentationAttribute", ((6, 2), (6, 27)), ["class"]);
5088-
("CompilationRepresentationAttribute", ((6, 2), (6, 27)), ["class"]);
50895083
("CompilationRepresentationAttribute", ((6, 2), (6, 27)), ["member"]);
50905084
("CompilationRepresentationFlags", ((6, 28), (6, 58)),
50915085
["enum"; "valuetype"]);

0 commit comments

Comments
 (0)