[TS] Audit and formalize the type relations used by usvm-ts
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- kotlin, node.js, typescript
- Domain
- compilers, devtools, testing-qa
Research direction
Start by mapping the consumers of TsTypeSystem operations, including UTypeRegion and USupportTypeStream, and classify the required relations. Use the TypeScript compiler API for static checks and Node.js for runtime predicates. Done means a checked-in design note, consumer map, executable conformance and property tests, documented unsupported cases, and focused follow-up issues for defects.
Written by the indexing model from the issue text.
Description
Execution scope and priority
The first deliverable is the consumer/relation map, laws and focused executable checks for type operations actually used by the current engine. Implement independent semantic fixes in focused follow-ups; do not combine a complete TypeScript type system, generic type framework and all engine changes into one PR.
Preserve conservative handling of uncertainty: UNKNOWN/unsupported is not semantic false and must not silently prune feasible alternatives. Static assignability, runtime membership and abstract-domain order may require distinct relations, but add APIs only for demonstrated consumers.
This broad audit is not a blanket blocker for #345/#360. If a concrete defect affects a selected experiment or built-in applicability, create a minimal regression/fix issue and block that affected task. Keep the full investigation checklist below as the audit scope, not a demand to implement unsupported language features before any experiment can run.
Context
PR #344 exposed a semantic coupling in the current TypeScript type implementation. TsTypeSystem.isSupertype is used by the symbolic type-constraint machinery, but related type decisions also affect structural property access, virtual call target selection, and runtime checks such as instanceof.
These operations do not necessarily use the same relation:
- TypeScript assignability is primarily structural and depends on compiler options;
instanceoffollows the JavaScript runtime prototype chain;- property reads and writes require a structural shape/capability constraint;
UTypeRegionneeds a coherent order and auxiliary operations for pruning symbolic type alternatives.
The fix in #344 introduces an internal nominal wrapper for instanceof so that a runtime hierarchy check does not change the established EtsAuxiliaryType behavior. This fixes the observed regression, but it also shows that the boundaries and laws of the type model are not yet explicit. TsTypeSystem is still marked as a draft, and several cases are unsupported or handled by provisional rules.
Problem
We need to establish which type relations USVM for TypeScript actually requires, formalize them, and verify that every consumer uses the appropriate relation.
The audit should cover at least:
- the intended meaning of
EtsAuxiliaryTypeand whether it is a TypeScript structural type, an abstract-domain constraint such as “has these properties”, or both; - nominal class hierarchy versus structural compatibility;
any,unknown,never,null, andundefined, including the assumedstrictNullChecksmode;- literal and primitive types;
- unions and intersections;
- arrays and tuples;
- function types and variance;
- classes, interfaces, unclear reference types, aliases, and synthetic structural types;
- coherence of
isSupertype,hasCommonSubtype,isFinal,isInstantiable,findSubtypes, andtopTypeStreamwith the expectations ofUTypeRegionandUSupportTypeStream.
Some current rules are candidates for errors, but should be checked against the chosen semantics rather than changed independently. Examples include intersection subtyping, bidirectional relations between auxiliary and class types, treatment of unknown with nullish types, and whether findSubtypes returns direct successors as required by UTypeSystem.
Proposed work
- Map the consumers. List every use of the type-system operations and classify it as static assignability, runtime membership/prototype testing, structural capability checking, call dispatch, or abstract-domain ordering.
- Specify the relations. Define the supported type universe, normalization rules, compiler-option assumptions, and the meaning of each public operation. State the laws required by the constraint engine, such as reflexivity/transitivity where applicable and coherence between subtype checks, common-subtype checks, finality, and subtype enumeration.
- Build an executable conformance matrix. Cover every supported pair/family of types and explicitly record unsupported cases and conservative fallbacks.
- Add independent oracles. Compare static assignability cases with the TypeScript compiler API under the selected compiler options. Check runtime predicates such as
instanceofwith JavaScript/Node.js examples instead of deriving them from static assignability. - Add property-based/metamorphic tests. Generate small type graphs and validate the stated laws and
UTypeRegionpruning behavior. Keep minimal counterexamples for every discovered violation. - Separate relations where necessary. If one API cannot represent the required semantics without ambiguity, introduce explicit operations or typed wrappers rather than encoding the distinction through accidental call-site conventions.
- Fix discovered defects in focused follow-up changes. Classify every known deviation as a sound over-approximation, an under-approximation, or an implementation bug.
Deliverables / acceptance criteria
- A checked-in design note defining the supported TypeScript and runtime type semantics and the assumptions made about compiler options.
- A consumer map showing which relation each analysis operation requires.
- An executable test matrix covering all currently supported
EtsTypefamilies. - Differential tests against the TypeScript compiler for static assignability and against Node.js for runtime type predicates.
- Property tests for the laws relied upon by
UTypeRegion/USupportTypeStream. - Minimal regression tests for every defect found during the audit.
- Unsupported or intentionally approximate cases are documented and handled conservatively.
- Follow-up implementation issues/PRs are split by independently reviewable semantic change.
Non-goal
This issue does not require implementing the entire TypeScript type system at once. Advanced features that are not represented by the current IR may remain unsupported, but their behavior must be explicit and must not silently make the symbolic type constraints unsound.
- Dominant language
- Kotlin
- Stars
- 33
- Forks
- 27
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 15
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from UnitTestBot/usvm
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
UnitTestBot/usvm#388 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
UnitTestBot/usvm#384 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
UnitTestBot/usvm#382 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
UnitTestBot/usvm#379 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
UnitTestBot/usvm#373 ·
All issues in UnitTestBot/usvm
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bitcoindevkit/bdk-ffi#1125 ·
-
Issue: Bug
Difficulty 1/5 Under an hour Newbie friendliness 91/100
OpenAPITools/openapi-generator#24978 ·
-
helsemelding-json-schema json-schema-core
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
contributor: external needs review
Difficulty 2/5 1-3 hours Newbie friendliness 82/100