Skip to content

Commit

Permalink
Remove obj_link_info field from GlobalResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jan 30, 2025
1 parent 55f58b9 commit bf02a8c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/flattening/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,8 @@ pub fn flatten_all_globals(linker: &mut Linker) {

fn flatten_global(linker: &mut Linker, global_obj : GlobalUUID, cursor: &mut Cursor<'_>) {
let errors_globals = GlobalResolver::take_errors_globals(linker, global_obj);
let globals = GlobalResolver::new(linker, global_obj, errors_globals);
let obj_link_info = linker.get_link_info(global_obj);
let globals = GlobalResolver::new(linker, obj_link_info, errors_globals);

let mut local_variable_context = LocalVariableContext::new_initial();

Expand Down
10 changes: 5 additions & 5 deletions src/flattening/typechecking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ pub fn typecheck_all_modules(linker: &mut Linker) {
for module_uuid in module_uuids {
let global_id = GlobalUUID::Module(module_uuid);
let errs_globals = GlobalResolver::take_errors_globals(linker, global_id);
let globals = GlobalResolver::new(linker, global_id, errs_globals);

let ctx_info_string = format!("Typechecking {}", &globals.obj_link_info.name);
let working_on: &Module = &linker.modules[module_uuid];
let globals = GlobalResolver::new(linker, &working_on.link_info, errs_globals);

let ctx_info_string = format!("Typechecking {}", &working_on.link_info.name);
println!("{ctx_info_string}");
let mut span_debugger = SpanDebugger::new(
&ctx_info_string,
&linker.files[globals.obj_link_info.file],
&linker.files[working_on.link_info.file],
);

let working_on: &Module = &linker.modules[module_uuid];

let mut context = TypeCheckingContext {
globals : &globals,
errors: &globals.errors,
Expand Down
5 changes: 3 additions & 2 deletions src/linker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,12 @@ enum NamespaceElement {
Colission(Box<[GlobalUUID]>),
}

/// The global object that collects all [Module]s, [StructType]s, and [NamedConstant]s that are in the SUS codebase.
/// The global singleton object that collects all [Module]s, [StructType]s, and [NamedConstant]s that are in the current SUS codebase.
///
/// There should only be one [Linker] globally.
///
/// See [LinkInfo], this contains shared data between all global objects in the whole progam.
///
/// It also keeps track of the global namespace.
///
/// Incremental operations such as adding and removing files can be performed on this
Expand Down Expand Up @@ -402,7 +404,6 @@ impl<'linker> FileBuilder<'linker> {
NamespaceElement::Global(g) => Box::new([*g, new_obj_id]),
NamespaceElement::Colission(coll) => {
let mut vec = std::mem::replace(coll, Box::new([])).into_vec();
vec.reserve(1); // Make sure to only allocate one extra element
vec.push(new_obj_id);
vec.into_boxed_slice()
}
Expand Down
6 changes: 1 addition & 5 deletions src/linker/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ struct LinkingErrorLocation {
pub struct GlobalResolver<'linker> {
linker: &'linker Linker,
pub file_data: &'linker FileData,
pub obj_link_info: &'linker LinkInfo,

pub errors: ErrorCollector<'linker>,
resolved_globals: RefCell<ResolvedGlobals>
Expand All @@ -63,15 +62,12 @@ impl<'linker> GlobalResolver<'linker> {

(errors, resolved_globals)
}
pub fn new(linker: &'linker Linker, global_obj: GlobalUUID, errors_globals: (ErrorStore, ResolvedGlobals)) -> Self {
let obj_link_info = linker.get_link_info(global_obj);

pub fn new(linker: &'linker Linker, obj_link_info: &'linker LinkInfo, errors_globals: (ErrorStore, ResolvedGlobals)) -> Self {
let file_data = &linker.files[obj_link_info.file];

GlobalResolver {
linker,
file_data,
obj_link_info,
errors: ErrorCollector::from_storage(errors_globals.0, obj_link_info.file, &linker.files),
resolved_globals: RefCell::new(errors_globals.1),
}
Expand Down

0 comments on commit bf02a8c

Please sign in to comment.