@@ -49,22 +49,22 @@ let read_file_cmi = f => {
4949 };
5050};
5151
52- let get_output_name = name => {
53- Filepath . String . remove_extension(name) ++ ".gr.wasm" ;
54- };
52+ let get_output_name = name => name ++ ".wasm" ;
5553
5654let find_ext_in_dir = (dir, name) => {
5755 let fullname = Filepath . String . concat(dir, name);
5856 let rec process_ext =
5957 fun
6058 | [] => None
6159 | [ ext , ... _ ] when file_exists (fullname ++ ext ) =>
62- Some ((fullname ++ ext, dir, name, ext ))
60+ Some ((fullname ++ ext, dir, name))
6361 | [ _ , ... tl ] => process_ext(tl);
6462 process_ext;
6563};
6664
67- let find_in_path_uncap = (~exts= [] , base_dir, path, name) => {
65+ let find_in_path_uncap =
66+ (~check_src= false , ~check_wasm= false , base_dir, path, name) => {
67+ let exts = (check_src ? [ "" ] : [] ) @ (check_wasm ? [ ".wasm" ] : [] );
6868 let rec try_dir =
6969 fun
7070 | [] => raise (Not_found )
@@ -75,12 +75,7 @@ let find_in_path_uncap = (~exts=[], base_dir, path, name) => {
7575 };
7676 };
7777 if (! Filepath . String . is_relative(name) && Fs_access . file_exists(name)) {
78- (
79- name,
80- Filepath . String . dirname(name),
81- Filepath . String . (remove_extension(basename(name))),
82- Filepath . String . extension(name),
83- );
78+ (name, Filepath . String . dirname(name), Filepath . String . basename(name));
8479 } else if (Filepath . String . is_relpath(name)) {
8580 try_dir([ base_dir] );
8681 } else {
@@ -177,9 +172,14 @@ let resolve_unit = (~search_path=?, ~cache=true, ~base_dir=?, unit_name) => {
177172 ) {
178173 | (true , Some (res )) => res
179174 | _ =>
180- let exts = [ ".gr" , ".gr.wasm" ] ;
181- let (_ , dir , basename , _ ) =
182- find_in_path_uncap(~exts, base_dir, path, unit_name);
175+ let (_ , dir , basename ) =
176+ find_in_path_uncap(
177+ ~check_src= true ,
178+ ~check_wasm= true ,
179+ base_dir,
180+ path,
181+ unit_name,
182+ );
183183 if (cache) {
184184 log_resolution(unit_name, dir, basename);
185185 } else {
@@ -202,30 +202,65 @@ let locate_module = (~disable_relpath=false, base_dir, path, unit_name) => {
202202 ) {
203203 | Some (m ) => m
204204 | None =>
205- let grain_src_exts = [ ".gr" ] ;
206205 let (dir , m ) =
207- switch (
208- find_in_path_uncap(~exts= [ ".gr.wasm" ] , base_dir, path, unit_name)
209- ) {
210- | (objpath , dir , basename , ext ) =>
206+ switch (find_in_path_uncap(~check_wasm= true , base_dir, path, unit_name)) {
207+ | (objpath , dir , basename ) =>
211208 ignore (log_resolution(unit_name, dir, basename));
212- switch (find_ext_in_dir(dir, basename, grain_src_exts)) {
213- | Some ((srcpath , _ , _ , _ )) => (
209+ let file = find_ext_in_dir(dir, basename, [ "" ] );
210+ switch (file) {
211+ | Some ((srcpath , _ , _ )) => (
214212 dir,
215213 GrainModule (srcpath, Some (objpath)),
216214 )
217215 | None => (dir, WasmModule (objpath))
218216 };
219217 | exception Not_found =>
220- let (srcpath , dir , _ , _ ) =
221- find_in_path_uncap(~exts = grain_src_exts , base_dir, path, unit_name);
218+ let (srcpath , dir , _ ) =
219+ find_in_path_uncap(~check_src = true , base_dir, path, unit_name);
222220 (dir, GrainModule (srcpath, None ));
223221 };
224222 PathTbl . add(current_located_module_cache() , (dir, unit_name), m);
225223 m;
226224 };
227225};
228226
227+ let try_locate_module =
228+ (~disable_relpath= false , base_dir, active_search_path, name, loc) => {
229+ let locate = locate_module(~disable_relpath, base_dir, active_search_path);
230+ Filepath . String . (
231+ try (locate(name)) {
232+ | Not_found =>
233+ if (check_suffix(name, ".gr" )) {
234+ let no_extension = chop_suffix(name, ".gr" );
235+ switch (locate(no_extension)) {
236+ | exception Not_found => error(No_module_file (loc, name, None ))
237+ | _ =>
238+ let name = ! is_relpath(name) ? no_extension : name;
239+ error(
240+ No_module_file (
241+ loc,
242+ name,
243+ Some ("did you mean \" " ++ no_extension ++ "\" ?" ),
244+ ),
245+ );
246+ };
247+ } else {
248+ switch (locate(name ++ ".gr" )) {
249+ | exception Not_found => error(No_module_file (loc, name, None ))
250+ | _ =>
251+ error(
252+ No_module_file (
253+ loc,
254+ name,
255+ Some ("did you mean \" " ++ name ++ ".gr\" ?" ),
256+ ),
257+ )
258+ };
259+ }
260+ }
261+ );
262+ };
263+
229264type dependency_node = {
230265 // dn_unit_name is a hashtable because we may have a situation
231266 // where A depends on B and C, and both B and C depend on D.
@@ -281,22 +316,12 @@ module Dependency_graph =
281316 List . map(
282317 name => {
283318 let located =
284- try (
285- locate_module(
286- base_dir,
287- active_search_path,
288- name. Location . txt,
289- )
290- ) {
291- | Not_found =>
292- error(
293- No_module_file (
294- name. Location . loc,
295- name. Location . txt,
296- None ,
297- ),
298- )
299- };
319+ try_locate_module(
320+ base_dir,
321+ active_search_path,
322+ name. Location . txt,
323+ name. Location . loc,
324+ );
300325 let out_file_name = located_to_out_file_name(located);
301326 let existing_dependency = lookup(out_file_name);
302327 switch (existing_dependency) {
@@ -331,16 +356,12 @@ module Dependency_graph =
331356 List . map(
332357 ((name, _)) => {
333358 let located =
334- try (locate_module(base_dir, active_search_path, name)) {
335- | Not_found =>
336- error(
337- No_module_file (
338- Location . in_file(dn. dn_file_name),
339- name,
340- None ,
341- ),
342- )
343- };
359+ try_locate_module(
360+ base_dir,
361+ active_search_path,
362+ name,
363+ Location . in_file(dn. dn_file_name),
364+ );
344365 let out_file_name = located_to_out_file_name(located);
345366 let existing_dependency = lookup(out_file_name);
346367 switch (existing_dependency) {
@@ -457,19 +478,14 @@ let locate_module_file = (~loc, ~disable_relpath=false, unit_name) => {
457478 let base_dir = Filepath . String . dirname(current_filename^ () );
458479 let path = Config . module_search_path() ;
459480 let located =
460- try (locate_module(~disable_relpath, base_dir, path, unit_name)) {
461- | Not_found => error(No_module_file (loc, unit_name, None ))
462- };
481+ try_locate_module(~disable_relpath, base_dir, path, unit_name, loc);
463482 located_to_out_file_name(located);
464483};
465484
466485let process_dependency = (~loc, ~base_file, unit_name) => {
467486 let base_dir = Filepath . String . dirname(base_file);
468487 let path = Config . module_search_path() ;
469- let located =
470- try (locate_module(~disable_relpath= false , base_dir, path, unit_name)) {
471- | Not_found => error(No_module_file (loc, unit_name, None ))
472- };
488+ let located = try_locate_module(base_dir, path, unit_name, loc);
473489 let out_file = located_to_out_file_name(located);
474490 let current_dep_node = Dependency_graph . lookup_filename(base_file);
475491 let existing_dependency = Dependency_graph . lookup_filename(out_file);
@@ -553,9 +569,9 @@ let report_error = ppf =>
553569 );
554570 }
555571 | No_module_file (_ , m , None ) =>
556- fprintf (ppf, "Missing file for module % s " , m)
572+ fprintf (ppf, "Missing file for module \" % s \" " , m)
557573 | No_module_file (_ , m , Some (msg )) =>
558- fprintf (ppf, "Missing file for module % s : % s " , m, msg);
574+ fprintf (ppf, "Missing file for module \" % s \" : % s " , m, msg);
559575
560576let () =
561577 Location . register_error_of_exn(
0 commit comments