Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize attribute checking #16036

Merged
merged 7 commits into from
Oct 10, 2023
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
8 changes: 4 additions & 4 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10779,6 +10779,7 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn
let mAttr = synAttr.Range
let typath, tyid = List.frontAndBack tycon
let tpenv = emptyUnscopedTyparEnv
let ad = env.eAccessRights

// if we're checking an attribute that was applied directly to a getter or a setter, then
// what we're really checking against is a method, not a property
Expand All @@ -10787,13 +10788,12 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn
let try1 n =
let tyid = mkSynId tyid.idRange n
let tycon = (typath @ [tyid])
let ad = env.eAccessRights

match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.UseInAttribute OpenQualified env.eNameResEnv ad tycon TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No with
| Exception err -> raze err
| _ -> 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)) )
ForceRaise ((try1 (tyid.idText + "Attribute")) |> otherwise (fun () -> (try1 tyid.idText)))
| Result(tinstEnclosing, tcref) -> success(TcTypeApp cenv NoNewTypars CheckCxs ItemOccurence.UseInAttribute env tpenv mAttr tcref tinstEnclosing [])

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ let GetAllUsesOfAllSymbols() =
traceProvider.ForceFlush() |> ignore
traceProvider.Dispose()

Assert.Equal(80, result.Length)
Assert.Equal(79, result.Length)
3 changes: 0 additions & 3 deletions tests/service/EditorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,6 @@ type Class1() =
su.Symbol.ToString(), (r.StartLine, r.StartColumn, r.EndLine, r.EndColumn))
|> shouldEqual
[|("LiteralAttribute", (3, 10, 3, 17))
("LiteralAttribute", (3, 10, 3, 17))
("member .ctor", (3, 10, 3, 17))
("val ModuleValue", (3, 20, 3, 31))
("val op_Addition", (6, 26, 6, 27))
Expand All @@ -793,11 +792,9 @@ type Class1() =
("Class1", (10, 5, 10, 11))
("member .ctor", (10, 5, 10, 11))
("LiteralAttribute", (11, 10, 11, 17))
("LiteralAttribute", (11, 10, 11, 17))
("member .ctor", (11, 10, 11, 17))
("val ClassValue", (11, 20, 11, 30))
("LiteralAttribute", (12, 17, 12, 24))
("LiteralAttribute", (12, 17, 12, 24))
("member .ctor", (12, 17, 12, 24))
("val StaticClassValue", (12, 27, 12, 43))
("val ClassValue", (14, 12, 14, 22))
Expand Down
6 changes: 0 additions & 6 deletions tests/service/ProjectAnalysisTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,6 @@ let ``Test Project14 all symbols`` () =
allUsesOfAllSymbols |> shouldEqual
[|("StructAttribute", "StructAttribute", "file1", ((4, 2), (4, 8)),
["attribute"]);
("StructAttribute", "StructAttribute", "file1", ((4, 2), (4, 8)), ["type"]);
("member .ctor", "StructAttribute", "file1", ((4, 2), (4, 8)), []);
("int", "int", "file1", ((5, 9), (5, 12)), ["type"]);
("int", "int", "file1", ((5, 9), (5, 12)), ["type"]);
Expand Down Expand Up @@ -2504,14 +2503,10 @@ let ``Test Project16 all symbols`` () =
allUsesOfAllSymbols |> shouldEqual
[|("ClassAttribute", "ClassAttribute", "sig1", ((8, 6), (8, 11)),
["attribute"], ["class"]);
("ClassAttribute", "ClassAttribute", "sig1", ((8, 6), (8, 11)), ["type"],
["class"]);
("member .ctor", "ClassAttribute", "sig1", ((8, 6), (8, 11)), [],
["member"]);
("ClassAttribute", "ClassAttribute", "sig1", ((12, 6), (12, 11)),
["attribute"], ["class"]);
("ClassAttribute", "ClassAttribute", "sig1", ((12, 6), (12, 11)), ["type"],
["class"]);
("member .ctor", "ClassAttribute", "sig1", ((12, 6), (12, 11)), [],
["member"]);
("int", "int", "sig1", ((16, 19), (16, 22)), ["type"], ["abbrev"]);
Expand Down Expand Up @@ -5085,7 +5080,6 @@ let ``Test Project40 all symbols`` () =
("IsNone", ((4, 33), (4, 41)), ["member"; "prop"; "funky"]);
("f", ((4, 4), (4, 5)), ["val"]);
("CompilationRepresentationAttribute", ((6, 2), (6, 27)), ["class"]);
("CompilationRepresentationAttribute", ((6, 2), (6, 27)), ["class"]);
("CompilationRepresentationAttribute", ((6, 2), (6, 27)), ["member"]);
("CompilationRepresentationFlags", ((6, 28), (6, 58)),
["enum"; "valuetype"]);
Expand Down