Skip to content

Commit

Permalink
Merge pull request #2737 from W95Psp/revert-attrs-restriction-local-n…
Browse files Browse the repository at this point in the history
…ames

Revert restriction from #2621: allow local names in attrs
  • Loading branch information
aseemr authored Oct 26, 2022
2 parents 20e3eed + 4a87742 commit 915a6f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 120 deletions.
110 changes: 4 additions & 106 deletions src/ocaml-output/FStar_TypeChecker_TcTerm.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions src/typechecker/FStar.TypeChecker.TcTerm.fst
Original file line number Diff line number Diff line change
Expand Up @@ -4334,17 +4334,7 @@ and tc_trivial_guard env t =
t,c

and tc_attributes env attrs =
// we don't want attributes to depend on local names (otherwise,
// this would imply dependent attributes, substitutions within
// attributes...) hence we get rid of [gamma] (the local names)
// below.
let env = { env with gamma = []; gamma_sig = []; gamma_cache = BU.smap_create 100 } in
try List.map (fun attr -> fst (tc_trivial_guard env attr)) attrs
with | Error (Fatal_VariableNotFound, msg, rng, ctx) -> // adding small hint for the user
raise (Error ( Fatal_VariableNotFound
, msg ^ ". Hint: local names are not allowed in attributes."
, rng, ctx))
| e -> raise e
List.map (fun attr -> fst (tc_trivial_guard env attr)) attrs

let tc_check_trivial_guard env t k =
let t, _, g = tc_check_tot_or_gtot_term env t k "" in
Expand Down
14 changes: 11 additions & 3 deletions tests/micro-benchmarks/BinderAttributes.fst
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ let f (#[@@@ description "x_imp"] x_imp:int) ([@@@ description "y"] y:string) :
let f2 (#[@@@ description "x_imp"]x_imp [@@@ description "y"]y : int) : Tot unit =
()

[@@expect_failure [230]]
let local_names_in_attributes_are_forbidden
= x:unit -> [@@@x]y:unit -> unit
let attributes_with_local_name (s: string)
= [@@@ description s] y:string -> unit

type binder =
{
Expand Down Expand Up @@ -148,3 +147,12 @@ let _ =
let expected = [[{ name = "x_imp"; qual = "Implicit"; desc = Some "x_imp"; }; { name = "y"; qual = "Explicit"; desc = Some "y"; }]] in
iter2 (fun ex bs -> validate ex bs) expected b
end

let _ =
// Substitution within attributes
assert True by begin
let foo = "foo" in
let t = attributes_with_local_name foo in
let bs = binders_from_arrow (quote t) in
validate [{ name = "y"; qual = "Explicit"; desc = Some foo; }] bs
end

0 comments on commit 915a6f8

Please sign in to comment.