From 26bb29e7d23bc1288243b991ff9c39329ef1544a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Inf=C3=BChr?= Date: Thu, 14 Nov 2024 20:57:15 +0100 Subject: [PATCH] frontend: Require package name in resolve_path --- dora-frontend/src/generator/tests.rs | 14 +- dora-frontend/src/stdlib_lookup.rs | 547 +++++++++++++++------------ 2 files changed, 321 insertions(+), 240 deletions(-) diff --git a/dora-frontend/src/generator/tests.rs b/dora-frontend/src/generator/tests.rs index 5ff596687..14fe13107 100644 --- a/dora-frontend/src/generator/tests.rs +++ b/dora-frontend/src/generator/tests.rs @@ -3256,7 +3256,7 @@ fn gen_reinterpret_float32_as_int32() { gen_fct( "fn f(a: Float32): Int32 { a.asInt32() }", |sa, code, fct| { - let fct_id = struct_method_by_name(sa, "Float32", "asInt32", false).unwrap(); + let fct_id = lookup_fct(sa, "std::primitives::Float32#asInt32"); let expected = vec![ PushRegister(r(0)), InvokeDirect(r(1), ConstPoolIdx(0)), @@ -3279,7 +3279,7 @@ fn gen_reinterpret_int32_as_float32() { gen_fct( "fn f(a: Int32): Float32 { a.asFloat32() }", |sa, code, fct| { - let fct_id = struct_method_by_name(sa, "Int32", "asFloat32", false).unwrap(); + let fct_id = lookup_fct(sa, "std::primitives::Int32#asFloat32"); let expected = vec![ PushRegister(r(0)), InvokeDirect(r(1), ConstPoolIdx(0)), @@ -3302,7 +3302,7 @@ fn gen_reinterpret_float64_as_int64() { gen_fct( "fn f(a: Float64): Int64 { a.asInt64() }", |sa, code, fct| { - let fct_id = struct_method_by_name(sa, "Float64", "asInt64", false).unwrap(); + let fct_id = lookup_fct(sa, "std::primitives::Float64#asInt64"); let expected = vec![ PushRegister(r(0)), InvokeDirect(r(1), ConstPoolIdx(0)), @@ -3325,7 +3325,7 @@ fn gen_reinterpret_int64_as_float64() { gen_fct( "fn f(a: Int64): Float64 { a.asFloat64() }", |sa, code, fct| { - let fct_id = struct_method_by_name(sa, "Int64", "asFloat64", false).unwrap(); + let fct_id = lookup_fct(sa, "std::primitives::Int64#asFloat64"); let expected = vec![ PushRegister(r(0)), InvokeDirect(r(1), ConstPoolIdx(0)), @@ -3384,7 +3384,7 @@ fn gen_convert_int32_to_float32() { gen_fct( "fn f(a: Int32): Float32 { a.toFloat32() }", |sa, code, fct| { - let fct_id = struct_method_by_name(sa, "Int32", "toFloat32", false).unwrap(); + let fct_id = lookup_fct(sa, "std::primitives::Int32#toFloat32"); let expected = vec![ PushRegister(r(0)), InvokeDirect(r(1), ConstPoolIdx(0)), @@ -3892,7 +3892,7 @@ fn gen_vec_load() { gen_fct( "fn f(x: Vec[Int32], idx: Int64): Int32 { x(idx) }", |sa, code, fct| { - let fct_id = lookup_fct(sa, "traits::IndexGet for collections::Vec#get"); + let fct_id = lookup_fct(sa, "std::traits::IndexGet for std::collections::Vec#get"); let expected = vec![ PushRegister(r(0)), PushRegister(r(1)), @@ -3916,7 +3916,7 @@ fn gen_vec_store() { gen_fct( "fn f(x: Vec[Int32], idx: Int64, value: Int32) { x(idx) = value; }", |sa, code, fct| { - let fct_id = lookup_fct(sa, "traits::IndexSet for collections::Vec#set"); + let fct_id = lookup_fct(sa, "std::traits::IndexSet for std::collections::Vec#set"); let expected = vec![ PushRegister(r(0)), PushRegister(r(1)), diff --git a/dora-frontend/src/stdlib_lookup.rs b/dora-frontend/src/stdlib_lookup.rs index a8032f128..2c765e4cb 100644 --- a/dora-frontend/src/stdlib_lookup.rs +++ b/dora-frontend/src/stdlib_lookup.rs @@ -2,8 +2,8 @@ use std::rc::Rc; use crate::sema::{ ClassDefinition, ClassDefinitionId, EnumDefinitionId, ExtensionDefinitionId, FctDefinitionId, - Field, FieldId, ImplDefinitionId, Intrinsic, ModuleDefinition, ModuleDefinitionId, Sema, - StructDefinitionId, TraitDefinitionId, TypeParamDefinition, Visibility, + Field, FieldId, ImplDefinitionId, Intrinsic, ModuleDefinition, Sema, StructDefinitionId, + TraitDefinitionId, TypeParamDefinition, Visibility, }; use crate::sym::{SymTable, SymbolKind}; use crate::ty::SourceType; @@ -12,8 +12,6 @@ use crate::interner::Name; use crate::ParsedType; pub fn lookup_known_fundamental_types(sa: &mut Sema) { - let stdlib_id = sa.stdlib_module_id(); - sa.known.structs.bool = Some(internal_struct( sa, "std::primitives::Bool", @@ -52,79 +50,79 @@ pub fn lookup_known_fundamental_types(sa: &mut Sema) { Some(SourceType::Float64), )); - sa.known.classes.string = Some(internal_class(sa, stdlib_id, "string::String")); + sa.known.classes.string = Some(internal_class(sa, "std::string::String")); - sa.known.classes.string_buffer = Some(find_class(sa, stdlib_id, "string::StringBuffer")); + sa.known.classes.string_buffer = Some(find_class(sa, "std::string::StringBuffer")); - sa.known.classes.atomic_int32 = Some(find_class(sa, stdlib_id, "thread::AtomicInt32")); - sa.known.classes.atomic_int64 = Some(find_class(sa, stdlib_id, "thread::AtomicInt64")); + sa.known.classes.atomic_int32 = Some(find_class(sa, "std::thread::AtomicInt32")); + sa.known.classes.atomic_int64 = Some(find_class(sa, "std::thread::AtomicInt64")); let cls = &mut sa.classes[sa.known.classes.string()]; cls.is_str = true; - sa.known.classes.array = Some(internal_class(sa, stdlib_id, "collections::Array")); + sa.known.classes.array = Some(internal_class(sa, "std::collections::Array")); let cls = &mut sa.classes[sa.known.classes.array()]; cls.is_array = true; - sa.known.classes.stacktrace = Some(find_class(sa, stdlib_id, "Stacktrace")); - sa.known.classes.stacktrace_element = Some(find_class(sa, stdlib_id, "StacktraceElement")); - sa.known.classes.thread = Some(find_class(sa, stdlib_id, "thread::Thread")); - - sa.known.traits.add = Some(find_trait(sa, stdlib_id, "traits::Add")); - sa.known.traits.bit_and = Some(find_trait(sa, stdlib_id, "traits::BitAnd")); - sa.known.traits.bit_or = Some(find_trait(sa, stdlib_id, "traits::BitOr")); - sa.known.traits.bit_xor = Some(find_trait(sa, stdlib_id, "traits::BitXor")); - sa.known.traits.comparable = Some(find_trait(sa, stdlib_id, "traits::Comparable")); - sa.known.traits.div = Some(find_trait(sa, stdlib_id, "traits::Div")); - sa.known.traits.equals = Some(find_trait(sa, stdlib_id, "traits::Equals")); - sa.known.traits.into_iterator = Some(find_trait(sa, stdlib_id, "traits::IntoIterator")); - sa.known.traits.iterator = Some(find_trait(sa, stdlib_id, "traits::Iterator")); - sa.known.traits.mul = Some(find_trait(sa, stdlib_id, "traits::Mul")); - sa.known.traits.mod_ = Some(find_trait(sa, stdlib_id, "traits::Mod")); - sa.known.traits.neg = Some(find_trait(sa, stdlib_id, "traits::Neg")); - sa.known.traits.not = Some(find_trait(sa, stdlib_id, "traits::Not")); - sa.known.traits.sar = Some(find_trait(sa, stdlib_id, "traits::Sar")); - sa.known.traits.shl = Some(find_trait(sa, stdlib_id, "traits::Shl")); - sa.known.traits.shr = Some(find_trait(sa, stdlib_id, "traits::Shr")); - sa.known.traits.stringable = Some(find_trait(sa, stdlib_id, "string::Stringable")); - sa.known.traits.sub = Some(find_trait(sa, stdlib_id, "traits::Sub")); - sa.known.traits.zero = Some(find_trait(sa, stdlib_id, "traits::Zero")); - sa.known.traits.index_get = Some(find_trait(sa, stdlib_id, "traits::IndexGet")); - sa.known.traits.index_set = Some(find_trait(sa, stdlib_id, "traits::IndexSet")); - - sa.known.enums.option = Some(find_enum(sa, stdlib_id, "primitives::Option")); - sa.known.enums.ordering = Some(find_enum(sa, stdlib_id, "traits::Ordering")); + sa.known.classes.stacktrace = Some(find_class(sa, "std::Stacktrace")); + sa.known.classes.stacktrace_element = Some(find_class(sa, "std::StacktraceElement")); + sa.known.classes.thread = Some(find_class(sa, "std::thread::Thread")); + + sa.known.traits.add = Some(find_trait(sa, "std::traits::Add")); + sa.known.traits.bit_and = Some(find_trait(sa, "std::traits::BitAnd")); + sa.known.traits.bit_or = Some(find_trait(sa, "std::traits::BitOr")); + sa.known.traits.bit_xor = Some(find_trait(sa, "std::traits::BitXor")); + sa.known.traits.comparable = Some(find_trait(sa, "std::traits::Comparable")); + sa.known.traits.div = Some(find_trait(sa, "std::traits::Div")); + sa.known.traits.equals = Some(find_trait(sa, "std::traits::Equals")); + sa.known.traits.into_iterator = Some(find_trait(sa, "std::traits::IntoIterator")); + sa.known.traits.iterator = Some(find_trait(sa, "std::traits::Iterator")); + sa.known.traits.mul = Some(find_trait(sa, "std::traits::Mul")); + sa.known.traits.mod_ = Some(find_trait(sa, "std::traits::Mod")); + sa.known.traits.neg = Some(find_trait(sa, "std::traits::Neg")); + sa.known.traits.not = Some(find_trait(sa, "std::traits::Not")); + sa.known.traits.sar = Some(find_trait(sa, "std::traits::Sar")); + sa.known.traits.shl = Some(find_trait(sa, "std::traits::Shl")); + sa.known.traits.shr = Some(find_trait(sa, "std::traits::Shr")); + sa.known.traits.stringable = Some(find_trait(sa, "std::string::Stringable")); + sa.known.traits.sub = Some(find_trait(sa, "std::traits::Sub")); + sa.known.traits.zero = Some(find_trait(sa, "std::traits::Zero")); + sa.known.traits.index_get = Some(find_trait(sa, "std::traits::IndexGet")); + sa.known.traits.index_set = Some(find_trait(sa, "std::traits::IndexSet")); + + sa.known.enums.option = Some(find_enum(sa, "std::primitives::Option")); + sa.known.enums.ordering = Some(find_enum(sa, "std::traits::Ordering")); } pub fn setup_prelude(sa: &mut Sema) { let stdlib_id = sa.stdlib_module_id(); let symbols = [ - "primitives::Bool", - "primitives::UInt8", - "primitives::Char", - "primitives::Int32", - "primitives::Int64", - "primitives::Int", - "primitives::Float32", - "primitives::Float64", - "string::String", - "collections::Array", - "collections::Vec", - "print", - "println", - "primitives::Option", - "unimplemented", - "unreachable", - "assert", - "primitives::Result", + "std::primitives::Bool", + "std::primitives::UInt8", + "std::primitives::Char", + "std::primitives::Int32", + "std::primitives::Int64", + "std::primitives::Int", + "std::primitives::Float32", + "std::primitives::Float64", + "std::string::String", + "std::collections::Array", + "std::collections::Vec", + "std::print", + "std::println", + "std::primitives::Option", + "std::unimplemented", + "std::unreachable", + "std::assert", + "std::primitives::Result", ]; let mut prelude_table = SymTable::new(); for name in &symbols { - let sym = resolve_name(sa, name, Some(stdlib_id)); + let sym = resolve_path(sa, name); let name = final_path_name(sa, name); let old_sym = prelude_table.insert(name, sym); assert!(old_sym.is_none()); @@ -132,7 +130,7 @@ pub fn setup_prelude(sa: &mut Sema) { { // include None and Some from Option - let enum_id = resolve_name(sa, "primitives::Option", Some(stdlib_id)) + let enum_id = resolve_path(sa, "std::primitives::Option") .to_enum() .expect("enum expected"); @@ -147,7 +145,7 @@ pub fn setup_prelude(sa: &mut Sema) { { // include Ok and Err from Result - let enum_id = resolve_name(sa, "primitives::Result", Some(stdlib_id)) + let enum_id = resolve_path(sa, "std::primitives::Result") .to_enum() .expect("enum expected"); @@ -175,13 +173,17 @@ fn final_path_name(sa: &mut Sema, path: &str) -> Name { } pub fn lookup_known_methods(sa: &mut Sema) { - sa.known.functions.string_equals = - Some(lookup_fct(sa, "traits::Equals for string::String#equals")); + sa.known.functions.string_equals = Some(lookup_fct( + sa, + "std::traits::Equals for std::string::String#equals", + )); - sa.known.functions.string_buffer_empty = Some(lookup_fct(sa, "string::StringBuffer#empty")); - sa.known.functions.string_buffer_append = Some(lookup_fct(sa, "string::StringBuffer#append")); + sa.known.functions.string_buffer_empty = + Some(lookup_fct(sa, "std::string::StringBuffer#empty")); + sa.known.functions.string_buffer_append = + Some(lookup_fct(sa, "std::string::StringBuffer#append")); sa.known.functions.string_buffer_to_string = - Some(lookup_fct(sa, "string::StringBuffer#toString")); + Some(lookup_fct(sa, "std::string::StringBuffer#toString")); } pub fn create_lambda_class(sa: &mut Sema) { @@ -214,14 +216,12 @@ pub fn create_lambda_class(sa: &mut Sema) { sa.known.classes.lambda = Some(class_id); } -fn find_class(sa: &Sema, module_id: ModuleDefinitionId, name: &str) -> ClassDefinitionId { - resolve_name(sa, name, Some(module_id)) - .to_class() - .expect("class expected") +fn find_class(sa: &Sema, name: &str) -> ClassDefinitionId { + resolve_path(sa, name).to_class().expect("class expected") } -fn internal_class(sa: &mut Sema, module_id: ModuleDefinitionId, name: &str) -> ClassDefinitionId { - let cls_id = find_class(sa, module_id, name); +fn internal_class(sa: &mut Sema, name: &str) -> ClassDefinitionId { + let cls_id = find_class(sa, name); let cls = &mut sa.classes[cls_id]; assert!(cls.is_internal); @@ -231,9 +231,7 @@ fn internal_class(sa: &mut Sema, module_id: ModuleDefinitionId, name: &str) -> C } fn internal_struct(sa: &mut Sema, name: &str, ty: Option) -> StructDefinitionId { - let struct_id = resolve_name(sa, name, None) - .to_struct() - .expect("struct expected"); + let struct_id = resolve_path(sa, name).to_struct().expect("struct expected"); let struct_ = &mut sa.structs[struct_id]; assert!(struct_.is_internal); @@ -243,7 +241,7 @@ fn internal_struct(sa: &mut Sema, name: &str, ty: Option) -> StructD struct_id } -pub fn resolve_name(sa: &Sema, name: &str, module_id: Option) -> SymbolKind { +pub fn resolve_path(sa: &Sema, name: &str) -> SymbolKind { let mut path = name.split("::"); let module_lookup = |sym: SymbolKind, name| { @@ -265,8 +263,7 @@ pub fn resolve_name(sa: &Sema, name: &str, module_id: Option let package = &sa.packages[*package_id]; SymbolKind::Module(package.top_level_module_id()) } else { - let sym = SymbolKind::Module(module_id.expect("missing module")); - module_lookup(sym, package_name) + panic!("unknown package {} in {}", package_name, name); }; for name in path { @@ -276,16 +273,12 @@ pub fn resolve_name(sa: &Sema, name: &str, module_id: Option sym } -fn find_trait(sa: &Sema, module_id: ModuleDefinitionId, name: &str) -> TraitDefinitionId { - resolve_name(sa, name, Some(module_id)) - .to_trait() - .expect("trait expected") +fn find_trait(sa: &Sema, name: &str) -> TraitDefinitionId { + resolve_path(sa, name).to_trait().expect("trait expected") } -fn find_enum(sa: &Sema, module_id: ModuleDefinitionId, name: &str) -> EnumDefinitionId { - resolve_name(sa, name, Some(module_id)) - .to_enum() - .expect("enum not found") +fn find_enum(sa: &Sema, name: &str) -> EnumDefinitionId { + resolve_path(sa, name).to_enum().expect("enum not found") } pub fn resolve_internal_functions(sa: &mut Sema) { @@ -312,616 +305,708 @@ pub fn resolve_internal_functions(sa: &mut Sema) { } fn resolve_functions(sa: &mut Sema) { - sa.known.functions.unreachable = Some(lookup_fct(sa, "unreachable")); - sa.known.functions.fatal_error = Some(lookup_fct(sa, "fatalError")); + sa.known.functions.unreachable = Some(lookup_fct(sa, "std::unreachable")); + sa.known.functions.fatal_error = Some(lookup_fct(sa, "std::fatalError")); } fn lookup_ordering(sa: &mut Sema) { - sa.known.functions.ordering_is_ge = Some(lookup_fct(sa, "Ordering#is_ge")); - sa.known.functions.ordering_is_gt = Some(lookup_fct(sa, "Ordering#is_gt")); - sa.known.functions.ordering_is_le = Some(lookup_fct(sa, "Ordering#is_le")); - sa.known.functions.ordering_is_lt = Some(lookup_fct(sa, "Ordering#is_lt")); + sa.known.functions.ordering_is_ge = Some(lookup_fct(sa, "std::Ordering#is_ge")); + sa.known.functions.ordering_is_gt = Some(lookup_fct(sa, "std::Ordering#is_gt")); + sa.known.functions.ordering_is_le = Some(lookup_fct(sa, "std::Ordering#is_le")); + sa.known.functions.ordering_is_lt = Some(lookup_fct(sa, "std::Ordering#is_lt")); } fn resolve_atomic_int32(sa: &mut Sema) { - intrinsic_method(sa, "thread::AtomicInt32#get", Intrinsic::AtomicInt32Get); - intrinsic_method(sa, "thread::AtomicInt32#set", Intrinsic::AtomicInt32Set); intrinsic_method( sa, - "thread::AtomicInt32#exchange", + "std::thread::AtomicInt32#get", + Intrinsic::AtomicInt32Get, + ); + intrinsic_method( + sa, + "std::thread::AtomicInt32#set", + Intrinsic::AtomicInt32Set, + ); + intrinsic_method( + sa, + "std::thread::AtomicInt32#exchange", Intrinsic::AtomicInt32Exchange, ); intrinsic_method( sa, - "thread::AtomicInt32#compareExchange", + "std::thread::AtomicInt32#compareExchange", Intrinsic::AtomicInt32CompareExchange, ); intrinsic_method( sa, - "thread::AtomicInt32#fetchAdd", + "std::thread::AtomicInt32#fetchAdd", Intrinsic::AtomicInt32FetchAdd, ); } fn resolve_atomic_int64(sa: &mut Sema) { - intrinsic_method(sa, "thread::AtomicInt64#get", Intrinsic::AtomicInt64Get); - intrinsic_method(sa, "thread::AtomicInt64#set", Intrinsic::AtomicInt64Set); intrinsic_method( sa, - "thread::AtomicInt64#exchange", + "std::thread::AtomicInt64#get", + Intrinsic::AtomicInt64Get, + ); + intrinsic_method( + sa, + "std::thread::AtomicInt64#set", + Intrinsic::AtomicInt64Set, + ); + intrinsic_method( + sa, + "std::thread::AtomicInt64#exchange", Intrinsic::AtomicInt64Exchange, ); intrinsic_method( sa, - "thread::AtomicInt64#compareExchange", + "std::thread::AtomicInt64#compareExchange", Intrinsic::AtomicInt64CompareExchange, ); intrinsic_method( sa, - "thread::AtomicInt64#fetchAdd", + "std::thread::AtomicInt64#fetchAdd", Intrinsic::AtomicInt64FetchAdd, ); } fn resolve_thread(sa: &mut Sema) { - intrinsic_method(sa, "thread::Thread#current", Intrinsic::ThreadCurrent); + intrinsic_method(sa, "std::thread::Thread#current", Intrinsic::ThreadCurrent); } fn resolve_string(sa: &Sema) { - intrinsic_method(sa, "string::String#size", Intrinsic::StrLen); - intrinsic_method(sa, "string::String#getByte", Intrinsic::StrGet); + intrinsic_method(sa, "std::string::String#size", Intrinsic::StrLen); + intrinsic_method(sa, "std::string::String#getByte", Intrinsic::StrGet); } fn resolve_uint8(sa: &mut Sema) { - intrinsic_method(sa, "primitives::UInt8#toInt64", Intrinsic::UInt8ToInt64); - intrinsic_method(sa, "primitives::UInt8#toInt32", Intrinsic::UInt8ToInt32); - intrinsic_method(sa, "primitives::UInt8#toChar", Intrinsic::UInt8ToChar); intrinsic_method( sa, - "traits::Equals for primitives::UInt8#equals", + "std::primitives::UInt8#toInt64", + Intrinsic::UInt8ToInt64, + ); + intrinsic_method( + sa, + "std::primitives::UInt8#toInt32", + Intrinsic::UInt8ToInt32, + ); + intrinsic_method(sa, "std::primitives::UInt8#toChar", Intrinsic::UInt8ToChar); + intrinsic_method( + sa, + "std::traits::Equals for std::primitives::UInt8#equals", Intrinsic::UInt8Eq, ); intrinsic_method( sa, - "traits::Comparable for primitives::UInt8#cmp", + "std::traits::Comparable for std::primitives::UInt8#cmp", Intrinsic::UInt8Cmp, ); } fn resolve_bool(sa: &Sema) { - intrinsic_method(sa, "primitives::Bool#toInt32", Intrinsic::BoolToInt32); - intrinsic_method(sa, "primitives::Bool#toInt64", Intrinsic::BoolToInt64); + intrinsic_method(sa, "std::primitives::Bool#toInt32", Intrinsic::BoolToInt32); + intrinsic_method(sa, "std::primitives::Bool#toInt64", Intrinsic::BoolToInt64); intrinsic_method( sa, - "traits::Equals for primitives::Bool#equals", + "std::traits::Equals for std::primitives::Bool#equals", Intrinsic::BoolEq, ); intrinsic_method( sa, - "traits::Not for primitives::Bool#not", + "std::traits::Not for std::primitives::Bool#not", Intrinsic::BoolNot, ); } fn resolve_char(sa: &Sema) { - intrinsic_method(sa, "primitives::Char#toInt64", Intrinsic::CharToInt64); - intrinsic_method(sa, "primitives::Char#toInt32", Intrinsic::CharToInt32); + intrinsic_method(sa, "std::primitives::Char#toInt64", Intrinsic::CharToInt64); + intrinsic_method(sa, "std::primitives::Char#toInt32", Intrinsic::CharToInt32); intrinsic_method( sa, - "traits::Equals for primitives::Char#equals", + "std::traits::Equals for std::primitives::Char#equals", Intrinsic::CharEq, ); intrinsic_method( sa, - "traits::Comparable for primitives::Char#cmp", + "std::traits::Comparable for std::primitives::Char#cmp", Intrinsic::CharCmp, ); } fn resolve_int32(sa: &Sema) { - intrinsic_method(sa, "primitives::Int32#toUInt8", Intrinsic::Int32ToUInt8); intrinsic_method( sa, - "primitives::Int32#toCharUnchecked", + "std::primitives::Int32#toUInt8", + Intrinsic::Int32ToUInt8, + ); + intrinsic_method( + sa, + "std::primitives::Int32#toCharUnchecked", Intrinsic::Int32ToChar, ); - intrinsic_method(sa, "primitives::Int32#toInt64", Intrinsic::Int32ToInt64); + intrinsic_method( + sa, + "std::primitives::Int32#toInt64", + Intrinsic::Int32ToInt64, + ); - intrinsic_method(sa, "primitives::Int32#toFloat32", Intrinsic::Int32ToFloat32); - intrinsic_method(sa, "primitives::Int32#toFloat64", Intrinsic::Int32ToFloat64); + intrinsic_method( + sa, + "std::primitives::Int32#toFloat32", + Intrinsic::Int32ToFloat32, + ); + intrinsic_method( + sa, + "std::primitives::Int32#toFloat64", + Intrinsic::Int32ToFloat64, + ); intrinsic_method( sa, - "primitives::Int32#asFloat32", + "std::primitives::Int32#asFloat32", Intrinsic::ReinterpretInt32AsFloat32, ); intrinsic_method( sa, - "traits::Equals for primitives::Int32#equals", + "std::traits::Equals for std::primitives::Int32#equals", Intrinsic::Int32Eq, ); intrinsic_method( sa, - "traits::Comparable for primitives::Int32#cmp", + "std::traits::Comparable for std::primitives::Int32#cmp", Intrinsic::Int32Cmp, ); intrinsic_method( sa, - "traits::Add for primitives::Int32#add", + "std::traits::Add for std::primitives::Int32#add", Intrinsic::Int32Add, ); intrinsic_method( sa, - "traits::Sub for primitives::Int32#sub", + "std::traits::Sub for std::primitives::Int32#sub", Intrinsic::Int32Sub, ); intrinsic_method( sa, - "traits::Mul for primitives::Int32#mul", + "std::traits::Mul for std::primitives::Int32#mul", Intrinsic::Int32Mul, ); intrinsic_method( sa, - "traits::Div for primitives::Int32#div", + "std::traits::Div for std::primitives::Int32#div", Intrinsic::Int32Div, ); intrinsic_method( sa, - "traits::Mod for primitives::Int32#modulo", + "std::traits::Mod for std::primitives::Int32#modulo", Intrinsic::Int32Mod, ); intrinsic_method( sa, - "primitives::Int32#wrappingAdd", + "std::primitives::Int32#wrappingAdd", Intrinsic::Int32AddUnchecked, ); intrinsic_method( sa, - "primitives::Int32#wrappingSub", + "std::primitives::Int32#wrappingSub", Intrinsic::Int32SubUnchecked, ); intrinsic_method( sa, - "primitives::Int32#wrappingMul", + "std::primitives::Int32#wrappingMul", Intrinsic::Int32MulUnchecked, ); intrinsic_method( sa, - "traits::BitOr for primitives::Int32#bitor", + "std::traits::BitOr for std::primitives::Int32#bitor", Intrinsic::Int32Or, ); intrinsic_method( sa, - "traits::BitAnd for primitives::Int32#bitand", + "std::traits::BitAnd for std::primitives::Int32#bitand", Intrinsic::Int32And, ); intrinsic_method( sa, - "traits::BitXor for primitives::Int32#bitxor", + "std::traits::BitXor for std::primitives::Int32#bitxor", Intrinsic::Int32Xor, ); intrinsic_method( sa, - "traits::Shl for primitives::Int32#shl", + "std::traits::Shl for std::primitives::Int32#shl", Intrinsic::Int32Shl, ); intrinsic_method( sa, - "traits::Shr for primitives::Int32#shr", + "std::traits::Shr for std::primitives::Int32#shr", Intrinsic::Int32Shr, ); intrinsic_method( sa, - "traits::Sar for primitives::Int32#sar", + "std::traits::Sar for std::primitives::Int32#sar", Intrinsic::Int32Sar, ); intrinsic_method( sa, - "primitives::Int32#rotateLeft", + "std::primitives::Int32#rotateLeft", Intrinsic::Int32RotateLeft, ); intrinsic_method( sa, - "primitives::Int32#rotateRight", + "std::primitives::Int32#rotateRight", Intrinsic::Int32RotateRight, ); intrinsic_method( sa, - "traits::Neg for primitives::Int32#neg", + "std::traits::Neg for std::primitives::Int32#neg", Intrinsic::Int32Neg, ); intrinsic_method( sa, - "primitives::Int32#wrappingNeg", + "std::primitives::Int32#wrappingNeg", Intrinsic::Int32NegUnchecked, ); intrinsic_method( sa, - "traits::Not for primitives::Int32#not", + "std::traits::Not for std::primitives::Int32#not", Intrinsic::Int32Not, ); intrinsic_method( sa, - "primitives::Int32#countZeroBits", + "std::primitives::Int32#countZeroBits", Intrinsic::Int32CountZeroBits, ); intrinsic_method( sa, - "primitives::Int32#countOneBits", + "std::primitives::Int32#countOneBits", Intrinsic::Int32CountOneBits, ); intrinsic_method( sa, - "primitives::Int32#countZeroBitsLeading", + "std::primitives::Int32#countZeroBitsLeading", Intrinsic::Int32CountZeroBitsLeading, ); intrinsic_method( sa, - "primitives::Int32#countOneBitsLeading", + "std::primitives::Int32#countOneBitsLeading", Intrinsic::Int32CountOneBitsLeading, ); intrinsic_method( sa, - "primitives::Int32#countZeroBitsTrailing", + "std::primitives::Int32#countZeroBitsTrailing", Intrinsic::Int32CountZeroBitsTrailing, ); intrinsic_method( sa, - "primitives::Int32#countOneBitsTrailing", + "std::primitives::Int32#countOneBitsTrailing", Intrinsic::Int32CountOneBitsTrailing, ); } fn resolve_float32(sa: &Sema) { - intrinsic_method(sa, "primitives::Float32#toInt32", Intrinsic::Float32ToInt32); - intrinsic_method(sa, "primitives::Float32#toInt64", Intrinsic::Float32ToInt64); intrinsic_method( sa, - "primitives::Float32#toFloat64", + "std::primitives::Float32#toInt32", + Intrinsic::Float32ToInt32, + ); + intrinsic_method( + sa, + "std::primitives::Float32#toInt64", + Intrinsic::Float32ToInt64, + ); + intrinsic_method( + sa, + "std::primitives::Float32#toFloat64", Intrinsic::PromoteFloat32ToFloat64, ); intrinsic_method( sa, - "primitives::Float32#asInt32", + "std::primitives::Float32#asInt32", Intrinsic::ReinterpretFloat32AsInt32, ); intrinsic_method( sa, - "traits::Equals for primitives::Float32#equals", + "std::traits::Equals for std::primitives::Float32#equals", Intrinsic::Float32Eq, ); intrinsic_method( sa, - "traits::Comparable for primitives::Float32#cmp", + "std::traits::Comparable for std::primitives::Float32#cmp", Intrinsic::Float32Cmp, ); intrinsic_method( sa, - "traits::Add for primitives::Float32#add", + "std::traits::Add for std::primitives::Float32#add", Intrinsic::Float32Add, ); intrinsic_method( sa, - "traits::Sub for primitives::Float32#sub", + "std::traits::Sub for std::primitives::Float32#sub", Intrinsic::Float32Sub, ); intrinsic_method( sa, - "traits::Mul for primitives::Float32#mul", + "std::traits::Mul for std::primitives::Float32#mul", Intrinsic::Float32Mul, ); intrinsic_method( sa, - "traits::Div for primitives::Float32#div", + "std::traits::Div for std::primitives::Float32#div", Intrinsic::Float32Div, ); intrinsic_method( sa, - "traits::Neg for primitives::Float32#neg", + "std::traits::Neg for std::primitives::Float32#neg", Intrinsic::Float32Neg, ); - intrinsic_method(sa, "primitives::Float32#isNan", Intrinsic::Float32IsNan); - intrinsic_method(sa, "primitives::Float32#abs", Intrinsic::Float32Abs); + intrinsic_method( + sa, + "std::primitives::Float32#isNan", + Intrinsic::Float32IsNan, + ); + intrinsic_method(sa, "std::primitives::Float32#abs", Intrinsic::Float32Abs); intrinsic_method( sa, - "primitives::Float32#roundToZero", + "std::primitives::Float32#roundToZero", Intrinsic::Float32RoundToZero, ); - intrinsic_method(sa, "primitives::Float32#roundUp", Intrinsic::Float32RoundUp); intrinsic_method( sa, - "primitives::Float32#roundDown", + "std::primitives::Float32#roundUp", + Intrinsic::Float32RoundUp, + ); + intrinsic_method( + sa, + "std::primitives::Float32#roundDown", Intrinsic::Float32RoundDown, ); intrinsic_method( sa, - "primitives::Float32#roundHalfEven", + "std::primitives::Float32#roundHalfEven", Intrinsic::Float32RoundHalfEven, ); - intrinsic_method(sa, "primitives::Float32#sqrt", Intrinsic::Float32Sqrt); + intrinsic_method(sa, "std::primitives::Float32#sqrt", Intrinsic::Float32Sqrt); } fn resolve_float64(sa: &Sema) { - intrinsic_method(sa, "primitives::Float64#toInt32", Intrinsic::Float64ToInt32); - intrinsic_method(sa, "primitives::Float64#toInt64", Intrinsic::Float64ToInt64); intrinsic_method( sa, - "primitives::Float64#toFloat32", + "std::primitives::Float64#toInt32", + Intrinsic::Float64ToInt32, + ); + intrinsic_method( + sa, + "std::primitives::Float64#toInt64", + Intrinsic::Float64ToInt64, + ); + intrinsic_method( + sa, + "std::primitives::Float64#toFloat32", Intrinsic::DemoteFloat64ToFloat32, ); intrinsic_method( sa, - "primitives::Float64#asInt64", + "std::primitives::Float64#asInt64", Intrinsic::ReinterpretFloat64AsInt64, ); intrinsic_method( sa, - "traits::Equals for primitives::Float64#equals", + "std::traits::Equals for std::primitives::Float64#equals", Intrinsic::Float64Eq, ); intrinsic_method( sa, - "traits::Comparable for primitives::Float64#cmp", + "std::traits::Comparable for std::primitives::Float64#cmp", Intrinsic::Float64Cmp, ); intrinsic_method( sa, - "traits::Add for primitives::Float64#add", + "std::traits::Add for std::primitives::Float64#add", Intrinsic::Float64Add, ); intrinsic_method( sa, - "traits::Sub for primitives::Float64#sub", + "std::traits::Sub for std::primitives::Float64#sub", Intrinsic::Float64Sub, ); intrinsic_method( sa, - "traits::Mul for primitives::Float64#mul", + "std::traits::Mul for std::primitives::Float64#mul", Intrinsic::Float64Mul, ); intrinsic_method( sa, - "traits::Div for primitives::Float64#div", + "std::traits::Div for std::primitives::Float64#div", Intrinsic::Float64Div, ); intrinsic_method( sa, - "traits::Neg for primitives::Float64#neg", + "std::traits::Neg for std::primitives::Float64#neg", Intrinsic::Float64Neg, ); - intrinsic_method(sa, "primitives::Float64#isNan", Intrinsic::Float64IsNan); + intrinsic_method( + sa, + "std::primitives::Float64#isNan", + Intrinsic::Float64IsNan, + ); - intrinsic_method(sa, "primitives::Float64#abs", Intrinsic::Float64Abs); + intrinsic_method(sa, "std::primitives::Float64#abs", Intrinsic::Float64Abs); intrinsic_method( sa, - "primitives::Float64#roundToZero", + "std::primitives::Float64#roundToZero", Intrinsic::Float64RoundToZero, ); - intrinsic_method(sa, "primitives::Float64#roundUp", Intrinsic::Float64RoundUp); intrinsic_method( sa, - "primitives::Float64#roundDown", + "std::primitives::Float64#roundUp", + Intrinsic::Float64RoundUp, + ); + intrinsic_method( + sa, + "std::primitives::Float64#roundDown", Intrinsic::Float64RoundDown, ); intrinsic_method( sa, - "primitives::Float64#roundHalfEven", + "std::primitives::Float64#roundHalfEven", Intrinsic::Float64RoundHalfEven, ); - intrinsic_method(sa, "primitives::Float64#sqrt", Intrinsic::Float64Sqrt); + intrinsic_method(sa, "std::primitives::Float64#sqrt", Intrinsic::Float64Sqrt); } fn resolve_int64(sa: &Sema) { intrinsic_method( sa, - "primitives::Int64#toCharUnchecked", + "std::primitives::Int64#toCharUnchecked", Intrinsic::Int64ToChar, ); - intrinsic_method(sa, "primitives::Int64#toInt32", Intrinsic::Int64ToInt32); - intrinsic_method(sa, "primitives::Int64#toUInt8", Intrinsic::Int64ToUInt8); + intrinsic_method( + sa, + "std::primitives::Int64#toInt32", + Intrinsic::Int64ToInt32, + ); + intrinsic_method( + sa, + "std::primitives::Int64#toUInt8", + Intrinsic::Int64ToUInt8, + ); - intrinsic_method(sa, "primitives::Int64#toFloat32", Intrinsic::Int64ToFloat32); - intrinsic_method(sa, "primitives::Int64#toFloat64", Intrinsic::Int64ToFloat64); + intrinsic_method( + sa, + "std::primitives::Int64#toFloat32", + Intrinsic::Int64ToFloat32, + ); + intrinsic_method( + sa, + "std::primitives::Int64#toFloat64", + Intrinsic::Int64ToFloat64, + ); intrinsic_method( sa, - "primitives::Int64#asFloat64", + "std::primitives::Int64#asFloat64", Intrinsic::ReinterpretInt64AsFloat64, ); intrinsic_method( sa, - "traits::Equals for primitives::Int64#equals", + "std::traits::Equals for std::primitives::Int64#equals", Intrinsic::Int64Eq, ); intrinsic_method( sa, - "traits::Comparable for primitives::Int64#cmp", + "std::traits::Comparable for std::primitives::Int64#cmp", Intrinsic::Int64Cmp, ); intrinsic_method( sa, - "traits::Add for primitives::Int64#add", + "std::traits::Add for std::primitives::Int64#add", Intrinsic::Int64Add, ); intrinsic_method( sa, - "traits::Sub for primitives::Int64#sub", + "std::traits::Sub for std::primitives::Int64#sub", Intrinsic::Int64Sub, ); intrinsic_method( sa, - "traits::Mul for primitives::Int64#mul", + "std::traits::Mul for std::primitives::Int64#mul", Intrinsic::Int64Mul, ); intrinsic_method( sa, - "traits::Div for primitives::Int64#div", + "std::traits::Div for std::primitives::Int64#div", Intrinsic::Int64Div, ); intrinsic_method( sa, - "traits::Mod for primitives::Int64#modulo", + "std::traits::Mod for std::primitives::Int64#modulo", Intrinsic::Int64Mod, ); intrinsic_method( sa, - "primitives::Int64#wrappingAdd", + "std::primitives::Int64#wrappingAdd", Intrinsic::Int64AddUnchecked, ); intrinsic_method( sa, - "primitives::Int64#wrappingSub", + "std::primitives::Int64#wrappingSub", Intrinsic::Int64SubUnchecked, ); intrinsic_method( sa, - "primitives::Int64#wrappingMul", + "std::primitives::Int64#wrappingMul", Intrinsic::Int64MulUnchecked, ); intrinsic_method( sa, - "traits::BitOr for primitives::Int64#bitor", + "std::traits::BitOr for std::primitives::Int64#bitor", Intrinsic::Int64Or, ); intrinsic_method( sa, - "traits::BitAnd for primitives::Int64#bitand", + "std::traits::BitAnd for std::primitives::Int64#bitand", Intrinsic::Int64And, ); intrinsic_method( sa, - "traits::BitXor for primitives::Int64#bitxor", + "std::traits::BitXor for std::primitives::Int64#bitxor", Intrinsic::Int64Xor, ); intrinsic_method( sa, - "traits::Shl for primitives::Int64#shl", + "std::traits::Shl for std::primitives::Int64#shl", Intrinsic::Int64Shl, ); intrinsic_method( sa, - "traits::Shr for primitives::Int64#shr", + "std::traits::Shr for std::primitives::Int64#shr", Intrinsic::Int64Shr, ); intrinsic_method( sa, - "traits::Sar for primitives::Int64#sar", + "std::traits::Sar for std::primitives::Int64#sar", Intrinsic::Int64Sar, ); intrinsic_method( sa, - "primitives::Int64#rotateLeft", + "std::primitives::Int64#rotateLeft", Intrinsic::Int64RotateLeft, ); intrinsic_method( sa, - "primitives::Int64#rotateRight", + "std::primitives::Int64#rotateRight", Intrinsic::Int64RotateRight, ); intrinsic_method( sa, - "traits::Neg for primitives::Int64#neg", + "std::traits::Neg for std::primitives::Int64#neg", Intrinsic::Int64Neg, ); intrinsic_method( sa, - "primitives::Int64#wrappingNeg", + "std::primitives::Int64#wrappingNeg", Intrinsic::Int64NegUnchecked, ); intrinsic_method( sa, - "traits::Not for primitives::Int64#not", + "std::traits::Not for std::primitives::Int64#not", Intrinsic::Int64Not, ); intrinsic_method( sa, - "primitives::Int64#countZeroBits", + "std::primitives::Int64#countZeroBits", Intrinsic::Int64CountZeroBits, ); intrinsic_method( sa, - "primitives::Int64#countOneBits", + "std::primitives::Int64#countOneBits", Intrinsic::Int64CountOneBits, ); intrinsic_method( sa, - "primitives::Int64#countZeroBitsLeading", + "std::primitives::Int64#countZeroBitsLeading", Intrinsic::Int64CountZeroBitsLeading, ); intrinsic_method( sa, - "primitives::Int64#countOneBitsLeading", + "std::primitives::Int64#countOneBitsLeading", Intrinsic::Int64CountOneBitsLeading, ); intrinsic_method( sa, - "primitives::Int64#countZeroBitsTrailing", + "std::primitives::Int64#countZeroBitsTrailing", Intrinsic::Int64CountZeroBitsTrailing, ); intrinsic_method( sa, - "primitives::Int64#countOneBitsTrailing", + "std::primitives::Int64#countOneBitsTrailing", Intrinsic::Int64CountOneBitsTrailing, ); } fn resolve_array(sa: &Sema) { - intrinsic_method(sa, "collections::Array#size", Intrinsic::ArrayLen); + intrinsic_method(sa, "std::collections::Array#size", Intrinsic::ArrayLen); intrinsic_method( sa, - "traits::IndexGet for collections::Array#get", + "std::traits::IndexGet for std::collections::Array#get", Intrinsic::ArrayGet, ); intrinsic_method( sa, - "traits::IndexSet for collections::Array#set", + "std::traits::IndexSet for std::collections::Array#set", Intrinsic::ArraySet, ); intrinsic_method( sa, - "collections::Array#unsafeNew", + "std::collections::Array#unsafeNew", Intrinsic::ArrayNewOfSize, ); - intrinsic_method(sa, "collections::Array#new", Intrinsic::ArrayWithValues); + intrinsic_method( + sa, + "std::collections::Array#new", + Intrinsic::ArrayWithValues, + ); } fn resolve_option(sa: &mut Sema) { - let fct_id = intrinsic_method(sa, "Option#isNone", Intrinsic::OptionIsNone); + let fct_id = intrinsic_method(sa, "std::Option#isNone", Intrinsic::OptionIsNone); sa.known.functions.option_is_none = Some(fct_id); - let fct_id = intrinsic_method(sa, "Option#isSome", Intrinsic::OptionIsSome); + let fct_id = intrinsic_method(sa, "std::Option#isSome", Intrinsic::OptionIsSome); sa.known.functions.option_is_some = Some(fct_id); - let fct_id = intrinsic_method(sa, "Option#getOrPanic", Intrinsic::OptionGetOrPanic); + let fct_id = intrinsic_method(sa, "std::Option#getOrPanic", Intrinsic::OptionGetOrPanic); sa.known.functions.option_unwrap = Some(fct_id); } @@ -933,8 +1018,6 @@ fn intrinsic_method(sa: &Sema, path: &str, intrinsic: Intrinsic) -> FctDefinitio } pub fn lookup_fct(sa: &Sema, path: &str) -> FctDefinitionId { - let module_id = sa.stdlib_module_id(); - if path.contains("#") { let parts = path.split("#").collect::>(); assert_eq!(parts.len(), 2); @@ -948,16 +1031,16 @@ pub fn lookup_fct(sa: &Sema, path: &str) -> FctDefinitionId { let trait_path = parts[0]; let extended_ty_path = parts[1]; - let trait_id = resolve_name(sa, trait_path, Some(module_id)) + let trait_id = resolve_path(sa, trait_path) .to_trait() .expect("trait expected"); - let extended_ty = resolve_name(sa, extended_ty_path, Some(module_id)); + let extended_ty = resolve_path(sa, extended_ty_path); let impl_id = lookup_impl_for_item(sa, trait_id, extended_ty).expect("impl not found"); lookup_fct_by_impl_id_and_name(sa, impl_id, method_name) .expect("method in impl not found") } else { - let extended_ty = resolve_name(sa, path, Some(module_id)); + let extended_ty = resolve_path(sa, path); let extension_id = lookup_extension_for_item(sa, extended_ty).expect("extension not found"); @@ -965,9 +1048,7 @@ pub fn lookup_fct(sa: &Sema, path: &str) -> FctDefinitionId { .expect("method in impl not found") } } else { - resolve_name(sa, path, Some(module_id)) - .to_fct() - .expect("function expected") + resolve_path(sa, path).to_fct().expect("function expected") } }