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

Some improvements wrt to plugins #3537

Merged
merged 8 commits into from
Oct 8, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Moving autoload logic into Compiler.Plugins
mtzguido committed Oct 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit c882dc9ee4f7abe3080bee62f7203f85656e54bf
15 changes: 15 additions & 0 deletions src/basic/FStar.Compiler.Plugins.fst
Original file line number Diff line number Diff line change
@@ -19,3 +19,18 @@ module FStar.Compiler.Plugins
open FStar.Compiler.Effect
open FStar.Compiler.Plugins.Base
module BU = FStar.Compiler.Util

(* Tries to load a plugin named like the extension. Returns true
if it could find a plugin with the proper name. This will fail hard
if loading the plugin fails. *)
let autoload_plugin (ext:string) : bool =
if Debug.any () then
BU.print1 "Trying to find a plugin for extension %s\n" ext;
match Options.find_file (ext ^ ".cmxs") with
| Some fn ->
if Debug.any () then
BU.print1 "Autoloading plugin %s ...\n" fn;
Plugins.Base.load_tactics [fn];
true
| None ->
false
5 changes: 5 additions & 0 deletions src/basic/FStar.Compiler.Plugins.fsti
Original file line number Diff line number Diff line change
@@ -18,3 +18,8 @@ module FStar.Compiler.Plugins

open FStar.Compiler.Effect
include FStar.Compiler.Plugins.Base

(* Tries to load a plugin named like the extension. Returns true
if it could find a plugin with the proper name. This will fail hard
if loading the plugin fails. *)
val autoload_plugin (ext:string) : bool
19 changes: 2 additions & 17 deletions src/parser/FStar.Parser.AST.Util.fst
Original file line number Diff line number Diff line change
@@ -747,26 +747,11 @@ let extension_parser_table : BU.smap extension_parser = FStar.Compiler.Util.smap
let register_extension_parser (ext:string) (parser:extension_parser) =
FStar.Compiler.Util.smap_add extension_parser_table ext parser

(* Tries to load a plugin named like the extension. Returns true
if it could find a plugin with the proper name. This will fail hard
if loading the plugin fails. *)
let autoload_plugin (ext:string) : bool =
if Debug.any () then
print1 "Trying to find a plugin for extension %s\n" ext;
match Options.find_file (ext ^ ".cmxs") with
| Some fn ->
if Debug.any () then
print1 "Autoloading plugin %s ...\n" fn;
Tactics.Load.load_tactics [fn];
true
| None ->
false

let lookup_extension_parser (ext:string) =
let r = FStar.Compiler.Util.smap_try_find extension_parser_table ext in
match r with
| None ->
if autoload_plugin ext
if Plugins.autoload_plugin ext
then FStar.Compiler.Util.smap_try_find extension_parser_table ext
else None
| _ -> r
@@ -789,7 +774,7 @@ let lookup_extension_lang_parser (ext:string) =
let r = FStar.Compiler.Util.smap_try_find extension_lang_parser_table ext in
match r with
| None ->
if autoload_plugin ext
if Plugins.autoload_plugin ext
then FStar.Compiler.Util.smap_try_find extension_lang_parser_table ext
else None
| _ -> r