Skip to content

Commit

Permalink
Add basic narrowing (#156)
Browse files Browse the repository at this point in the history
- Currently basic equality
- Add Type::Narrowed
- Add narrowing for `typeof`
- Add narrowing for dependent booleans
- Add negation and filtering
- Add conjugtions
- Add disjoint checking to equality to fix `??` == undefined issue
- Improve LocalInformation merging around final events
- Prototypes with `instanceof`
- Add `Filter` helper
- Property access narrowing
- Add De Morgan's laws for narrowing && and ||
- Add asserts return type checking
- Add narrowing lookup for conditional result for printing and access
- Narrowing from free variable
  • Loading branch information
kaleidawave authored Aug 20, 2024
1 parent 0856014 commit 793f54d
Show file tree
Hide file tree
Showing 38 changed files with 2,323 additions and 854 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ env:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
checker/fuzz/target
parser/fuzz/target
jobs:
validity:
Expand Down Expand Up @@ -304,6 +306,9 @@ jobs:
# find fuzz/artifacts -type f -print -exec xxd {} \; -exec cargo fuzz fmt -s none module_roundtrip_structured {} \;; false;
# fi
fi
ls .
ls target
working-directory: checker/fuzz

clippy:
Expand Down
Binary file modified checker/definitions/internal.ts.d.bin
Binary file not shown.
40 changes: 36 additions & 4 deletions checker/definitions/simple.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ declare function context_id(): void
@Constant
declare function context_id_chain(): void

// A function, as it should be!
@Constant
declare function satisfies<T>(t: T): T
declare function debug_state(): void

// A function, as it should be!
@Constant
declare function compile_type_to_object<T>(): any
declare function satisfies<T>(t: T): T

interface ImportEnv {
[key: string]: string;
Expand Down Expand Up @@ -76,7 +76,7 @@ declare class Array<T> {
const { length } = this, mapped: Array<U> = [];
let i: number = 0;
while (i < length) {
const value = this?.[i];
const value = this[i];
const newValue = cb(value, i++);
mapped.push(newValue)
}
Expand Down Expand Up @@ -361,6 +361,38 @@ declare class Object {
// Object.setProtoTypeOf(n, prototype);
// return n
// }

static keys(on: { [s: string]: any }): Array<string> {
const keys: Array<string> = [];
for (const key in on) {
keys.push(key);
}
return keys
}

static values(on: { [s: string]: any }): Array<any> {
const values: Array<any> = [];
for (const key in on) {
values.push(on[key]);
}
return values
}

static entries(on: { [s: string]: any }): Array<[string, any]> {
const entries: Array<[string, any]> = [];
for (const key in on) {
entries.push([key, on[key]]);
}
return entries
}

// TODO multiple arguments
static assign(target: object, source: object): object {
for (const key in source) {
target[key] = source[key]
}
return target
}
}

declare class RegExp {
Expand Down
12 changes: 4 additions & 8 deletions checker/examples/calculate_subtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ fn contributions(environment: &mut Environment, types: &mut TypeStore) {
environment.new_explicit_type_parameter("T", Some(TypeId::NUMBER_TYPE), None, types);

// create `{}` and add `inner: T`
let object = types.new_anonymous_interface_type();
let inner = PropertyKey::String(std::borrow::Cow::Owned("inner".to_owned()));
environment.info.register_property(
object,
let object = types.new_anonymous_interface_type(vec![(
Publicity::Public,
inner.clone(),
PropertyKey::String(std::borrow::Cow::Owned("inner".to_owned())),
PropertyValue::Value(generic_parameter.type_id),
source_map::SpanWithSource::NULL,
);
)]);

let or = types.new_or_type(generic_parameter.type_id, object);
let parameter = types.new_function_parameter(or);
Expand All @@ -77,7 +73,7 @@ fn contributions(environment: &mut Environment, types: &mut TypeStore) {
);
basis.append(
Publicity::Public,
inner,
PropertyKey::String(std::borrow::Cow::Owned("inner".to_owned())),
PropertyValue::Value(five),
source_map::SpanWithSource::NULL,
&mut environment.info,
Expand Down
2 changes: 2 additions & 0 deletions checker/examples/run_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn main() {
let debug_types = args.iter().any(|item| item == "--debug-types");
let no_lib = args.iter().any(|item| item == "--no-lib");
let debug_dts = args.iter().any(|item| item == "--debug-dts");
let extras = args.iter().any(|item| item == "--extras");

let now = Instant::now();

Expand All @@ -44,6 +45,7 @@ fn main() {
record_all_assignments_and_reads: true,
max_inline_count: 600,
debug_dts,
extra_syntax: extras,
..Default::default()
};

Expand Down
1 change: 0 additions & 1 deletion checker/fuzz/fuzz_targets/check_project_naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use ezno_checker::{check_project, synthesis, TypeCheckOptions};
use libfuzzer_sys::{fuzz_target, Corpus};
use std::collections::HashSet;
use std::str;

/// check_project_naive throws random strings into the ezno checker, validating that none of them make the checker panic.
Expand Down
Loading

0 comments on commit 793f54d

Please sign in to comment.