Source identity¶
Core hashes beside the grammar-keyed hashes of a source's bytes and of its alpha-normalized statements.
identity
¶
Content identity of QVR source: core hashes beside source hashes.
A program has two identities, recorded separately:
- its core identity: the content hash of every checked QIEC declaration
(
module_hashes), domain-separated by the core format, so any surface syntax that elaborates to the same core has the same hashes and a syntactic migration hop preserves them; - its source identity: one hash per top-level statement of the source, keyed by the panproto commit of the grammar the source is written in, plus the hash of the exact bytes.
A statement's source hash is alpha-normalized as far as the source's own name
analysis (analyze_names) reaches:
comments, blank lines, indentation width, spacing, and number spelling are
dropped; a name the statement declares becomes its position among the
statement's declarations; a local binder and the references it binds become
the ordinal of the name's first occurrence; and a reference to a name another
statement declares becomes that statement's source hash, with mutually
referring statements hashed as one canonically ordered component, as in the
core. Every other token (keywords, operators, literals, option keys, builtin
names, the labels of a deduction's body) is kept as written.
The source identity covers what the checked core does not yet record (a relation's arcs, a loss, a declared morphism type, the learnability of a deduction rule, ...), which is why a fit is keyed by both. Because it is a function of the surface syntax, a migration hop may change it, and it is recorded with the grammar commit it was computed under.
IdentityError
¶
Bases: ValueError
A source cannot be identified: it does not parse or does not check.
SourceHash
didactic-model
¶
Bases: Model
The hash of a source's exact bytes.
| PARAMETER | DESCRIPTION |
|---|---|
grammar
|
The panproto schema commit of the grammar the source is written in.
TYPE:
|
digest
|
The BLAKE3 digest of the bytes.
TYPE:
|
StatementHash
didactic-model
¶
Bases: Model
The alpha-normalized source hash of one top-level statement.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
The statement's grammar kind (
TYPE:
|
names
|
The names it declares, in order (metadata).
TYPE:
|
hash
|
Its source hash: the component hash when no other statement refers
back to it, else
TYPE:
|
ProgramIdentity
didactic-model
¶
ProgramIdentity(*, core: ModuleHashes, statements: tuple[StatementHash, ...], source: SourceHash, digest: str)
Bases: Model
Every identity of one checked source.
| PARAMETER | DESCRIPTION |
|---|---|
core
|
The core hashes of its checked declarations.
TYPE:
|
statements
|
The source hash of each top-level statement, in source order.
TYPE:
|
source
|
The hash of the exact bytes.
TYPE:
|
digest
|
The digest of the core module digest and the multiset of statement hashes under the grammar commit: what a fit of this program is keyed by.
TYPE:
|
head_grammar
¶
The panproto schema commit of the grammar this checkout parses.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The commit pinned for |
source_hash
¶
source_hash(source: bytes, *, grammar: str) -> SourceHash
The hash of a source's exact bytes.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The bytes.
TYPE:
|
grammar
|
The schema commit of the grammar they are written in.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SourceHash
|
The grammar commit with the BLAKE3 digest of the bytes. |
Source code in src/quivers/incremental/identity.py
statement_hashes
¶
statement_hashes(source: bytes, tree: _Tree, names: FileNames) -> tuple[StatementHash, ...]
The alpha-normalized source hash of every top-level statement.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The file's bytes.
TYPE:
|
tree
|
Its parse tree.
TYPE:
|
names
|
Its name analysis.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[StatementHash, ...]
|
One hash per statement, in source order. A statement's hash covers the hashes of the statements it refers to, so it changes when they do; statements that refer to one another are hashed as one component. |
| RAISES | DESCRIPTION |
|---|---|
IdentityError
|
If a reference cannot be resolved. |
Source code in src/quivers/incremental/identity.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
check_source
¶
check_source(source: bytes, *, module_name: str, file_path: str, roots: tuple[str | Path, ...] = ()) -> QiecModule
Interpret and check a source, with its imports, down to its QIEC module.
The source is the root of a module graph (quivers.dsl.modules): its
imports are found in the standard library and below roots, and the
flat program is what is checked and hashed.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The source.
TYPE:
|
module_name
|
The name stable identities derive from (metadata of every hash).
TYPE:
|
file_path
|
The path diagnostics name.
TYPE:
|
roots
|
Directories the source's imported module paths are relative to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecModule
|
The checked module. |
| RAISES | DESCRIPTION |
|---|---|
IdentityError
|
If the source does not parse, its module graph does not load or resolve, its QIEC lowering reports a diagnostic (located in the module it comes from), or a program was not elaborated. A module that failed to check has no meaning to hash, and a module missing a program would hash as if the program were absent. |
Source code in src/quivers/incremental/identity.py
statements_digest
¶
statements_digest(source: str | bytes, *, file_path: str = '<source>', grammar: str | None = None) -> str
The digest of a source's statement hashes, without checking it.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The source text.
TYPE:
|
file_path
|
The path diagnostics name.
TYPE:
|
grammar
|
The schema commit of the grammar the source is written in;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest of the grammar commit and the multiset of the statements' alpha-normalized source hashes: invariant under renaming, reordering, comments, and formatting, and changed by any other edit to any statement. |
| RAISES | DESCRIPTION |
|---|---|
IdentityError
|
If the source does not parse. |
Source code in src/quivers/incremental/identity.py
identify
¶
identify(source: str | bytes, *, module_name: str, file_path: str = '<source>', grammar: str | None = None, roots: tuple[str | Path, ...] = ()) -> ProgramIdentity
Every identity of one source file.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The source text.
TYPE:
|
module_name
|
The module name stable identities derive from.
TYPE:
|
file_path
|
The path diagnostics name.
TYPE:
|
grammar
|
The schema commit of the grammar the source is written in;
TYPE:
|
roots
|
Directories the source's imported module paths are relative to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ProgramIdentity
|
Its core hashes, statement source hashes, and source hash. |
| RAISES | DESCRIPTION |
|---|---|
IdentityError
|
If the source does not parse or check. |