@@ -9,6 +9,7 @@ use codespan_reporting::term::termcolor::{BufferedStandardStream, ColorChoice, W
99use crate :: core:: binary:: { self , BufferError , ReadError } ;
1010use crate :: files:: { FileId , Files } ;
1111use crate :: source:: { ByteRange , Span , StringInterner } ;
12+ use crate :: surface:: elaboration:: ItemEnv ;
1213use crate :: surface:: { self , elaboration} ;
1314use crate :: { core, BUG_REPORT_URL } ;
1415
@@ -192,7 +193,8 @@ impl<'surface, 'core> Driver<'surface, 'core> {
192193 }
193194
194195 pub fn elaborate_and_emit_module ( & mut self , file_id : FileId , pretty_core : bool ) -> Status {
195- let mut context = elaboration:: Context :: new ( & self . interner , & self . core_scope ) ;
196+ let mut context =
197+ elaboration:: Context :: new ( file_id, & self . interner , & self . core_scope , ItemEnv :: new ( ) ) ;
196198
197199 let surface_module = self . parse_module ( file_id) ;
198200 let module = context. elab_module ( & self . core_scope , & surface_module, & mut |m| {
@@ -217,7 +219,8 @@ impl<'surface, 'core> Driver<'surface, 'core> {
217219 }
218220
219221 pub fn elaborate_and_emit_term ( & mut self , file_id : FileId ) -> Status {
220- let mut context = elaboration:: Context :: new ( & self . interner , & self . core_scope ) ;
222+ let mut context =
223+ elaboration:: Context :: new ( file_id, & self . interner , & self . core_scope , ItemEnv :: new ( ) ) ;
221224
222225 // Parse and elaborate the term
223226 let surface_term = self . parse_term ( file_id) ;
@@ -241,7 +244,8 @@ impl<'surface, 'core> Driver<'surface, 'core> {
241244 }
242245
243246 pub fn normalise_and_emit_term ( & mut self , file_id : FileId ) -> Status {
244- let mut context = elaboration:: Context :: new ( & self . interner , & self . core_scope ) ;
247+ let mut context =
248+ elaboration:: Context :: new ( file_id, & self . interner , & self . core_scope , ItemEnv :: new ( ) ) ;
245249
246250 // Parse and elaborate the term
247251 let surface_term = self . parse_term ( file_id) ;
@@ -277,22 +281,27 @@ impl<'surface, 'core> Driver<'surface, 'core> {
277281
278282 let initial_buffer = binary:: Buffer :: from ( buffer_data) ;
279283 let mut binary_context = binary:: Context :: new ( initial_buffer) ;
280- let mut elab_context = elaboration :: Context :: new ( & self . interner , & self . core_scope ) ;
284+ let mut item_env = ItemEnv :: new ( ) ;
281285
282286 // Parse and elaborate a module if one was provided
283287 if let Some ( file_id) = module_file_id {
288+ let mut elab_context =
289+ elaboration:: Context :: new ( file_id, & self . interner , & self . core_scope , item_env) ;
284290 let surface_module = self . parse_module ( file_id) ;
285291 let module = elab_context. elab_module ( & self . core_scope , & surface_module, & mut |m| {
286292 self . emit_diagnostic ( m. to_diagnostic ( & self . interner ) ) ;
287293 } ) ;
288294 // Add it to the binary context
289295 binary_context. add_module ( & module) ;
296+ item_env = elab_context. finish ( ) ;
290297 }
291298
292299 // Parse and elaborate the supplied format with the items from the
293300 // supplied in the module in scope. This is still a bit of a hack, and
294301 // will need to be revisited if we need to support multiple modules, but
295302 // it works for now!
303+ let mut elab_context =
304+ elaboration:: Context :: new ( format_file_id, & self . interner , & self . core_scope , item_env) ;
296305 let surface_format = self . parse_term ( format_file_id) ;
297306 let format = elab_context. elab_format ( & self . core_scope , & surface_format, & mut |m| {
298307 self . emit_diagnostic ( m. to_diagnostic ( & self . interner ) ) ;
@@ -333,17 +342,16 @@ impl<'surface, 'core> Driver<'surface, 'core> {
333342 fn parse_module ( & ' surface self , file_id : FileId ) -> surface:: Module < ' surface , ByteRange > {
334343 let source = self . files . get ( file_id) . unwrap ( ) . source ( ) ;
335344 let ( module, messages) =
336- surface:: Module :: parse ( & self . interner , & self . surface_scope , file_id , source) ;
337- self . emit_diagnostics ( messages. into_iter ( ) . map ( |m| m. to_diagnostic ( ) ) ) ;
345+ surface:: Module :: parse ( & self . interner , & self . surface_scope , source) ;
346+ self . emit_diagnostics ( messages. into_iter ( ) . map ( |m| m. to_diagnostic ( file_id ) ) ) ;
338347
339348 module
340349 }
341350
342351 fn parse_term ( & ' surface self , file_id : FileId ) -> surface:: Term < ' surface , ByteRange > {
343352 let source = self . files . get ( file_id) . unwrap ( ) . source ( ) ;
344- let ( term, messages) =
345- surface:: Term :: parse ( & self . interner , & self . surface_scope , file_id, source) ;
346- self . emit_diagnostics ( messages. into_iter ( ) . map ( move |m| m. to_diagnostic ( ) ) ) ;
353+ let ( term, messages) = surface:: Term :: parse ( & self . interner , & self . surface_scope , source) ;
354+ self . emit_diagnostics ( messages. into_iter ( ) . map ( move |m| m. to_diagnostic ( file_id) ) ) ;
347355
348356 term
349357 }
0 commit comments