Repository navigation
fix(emit/check/syntax): substitute generic struct N5 maps, infer transitive comparable, and lower new(generic[...]) (#744, #722) - #745
Open
sonson0910 wants to merge 1 commit into
Conversation
…sitive comparable, and lower new(generic[...])
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #744
Fixes #722
Summary
Sweeps the remaining generic-struct and generic-function lowering, parsing, and check-time validation holes noted in #722 / #663:
hy-emit(zeroinit.rs,lib.rs): Generic struct N5 map zero-value substitution (var b box[u8],box[u8]{},new(box[u8]), nested generic structs):populate_n5_structsnow records generic structs alongside their fixed-pointcomparableparameter constraints ("table[k:comparable,v]").n5_resolve_struct_fieldsandsubst_type_exprsubstitute concrete type arguments into the declared generic struct fields (including nested generic struct fields,map[K]V,option[T], slices, arrays, pointers, channels, andfntypes) sovar b box[u8],box[u8]{},new(box[u8]), andvar h holder[i16]allocate Concrete Go map zero values (map[string]uint8{}) instead of skipping N5 or leaving parametric type names unsubstituted.hy-emit(lib.rs): Fixed-point transitive, receiver-method, constructor, and equality (==/!=/match)comparableconstraint inference:comparableconstraints transitively across generic structs (struct wrapper[a, b] { inner table[a, b] }->[a comparable, b any]), throughset[t], and throughoption[t]/[N]tmap keys.comparableconstraints on generic receiver methods (fn (s *set_buf[x]) unique() map[x]bool->func (s *set_buf[x]) unique() map[x]boolwithset_buf[x comparable]), generic constructors (fn table.new[k, v]() table[k, v]->[k comparable, v any]),new(table[k, v]), value-typed==/!=comparisons (fn same[t](x t, y t) bool { return x == y }->[t comparable]), and non-optionmatchsubjects.hy-syntax(parser.rs) &hy-emit(expr.rs):new(generic[...])and pointer type args (box[*int]{}):peek_generic_argsto recognize balanced type-argument brackets containing*,[,],<-,fn,(,), and,, and allows)immediately after]sonew(pair[u8, i16])andbox[*int]{}parse as generic type arguments.emit_newto extract the fullTypeExprviaSelf::new_arg_type_exprand format viaself.type_text(&ty)sonew(box[u8])lowers tonew(box[uint8])(or&box[uint8]{...}when N5 applies).hy-check(buildable.rs): Validatenew(T)type arguments and resolve pointer result kind fornew(generic[...]):new(T)'s type argument viaself.ty(&new_ty)so uninstantiatednew(box)and wrong-aritynew(pair[int])fail closed withHYB-E4001.call_result_kindsandnew_kindsonew(box[int])resolves toKind::Ptr(Box::new(Kind::Named("box"))).Verification
cargo test --manifest-path compiler/Cargo.toml --test n5_zero_map_lowering --test resolve_generics_and_const_closurescargo test --manifest-path compiler/Cargo.tomlpasses with 0 failures.