Register typed GUI capabilities and reject incompatible presenters early
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@
|
||||
| mount.rs | Typed per-occurrence methods and nominal Bounds results, managed contexts, weak reverse links, ordered mount/unmount hooks, geometry and focus queries |
|
||||
| events.rs | Bounded native input transport with kind-specific tab-drop/desktop-position metadata to the owning VM |
|
||||
| event_dispatch.rs | Typed managed Event/Subscription methods, weak Subscription tokens, Block-owned connections and occurrence-specific capture/target/bubble through a budgeted VM driver |
|
||||
| protocols.rs | Register explicit Visual/EventTarget/Children (including insert)/Presentable managed traits and native type declarations |
|
||||
| protocols.rs | Register typed Visual/EventTarget/Children (including insert)/Presentable managed trait requirements, using canonical signatures and explicit native type declarations |
|
||||
| presentation.rs | Per-window layout, Mount/focus/tab state and read dependencies; VM changes fan out before any view consumes work |
|
||||
| tasks.rs | Typed Task/ui.after methods, managed owner scopes and callbacks, weak timer index, request-key replacement, lifecycle cancellation and budgeted worker delivery |
|
||||
| tabs.rs | Immutable tab chrome, shared draw/hit geometry, overflow navigation, drag gaps/anchors/insertion markers and opaque published Page identities |
|
||||
|
||||
+2
-2
@@ -1103,9 +1103,9 @@ Declared fields are checked at construction and set_attr writes through the same
|
||||
|
||||
Native methods now publish positional CallArity intervals, checked by the VM before invocation. Source defaults and bound receivers participate in the same query. Traits validate acceptance of their canonical count including self and reject native methods without metadata. Event listeners/onClick require Function metadata accepting zero arguments or one Event, preferring Event if both work. Binding computes and Task callbacks require zero-argument acceptance before registration/replacement. Generic Type constructor reflection and complete native signature coverage remain separate gaps. See examples/native-signatures.endor.
|
||||
|
||||
Native CallSignature checks resolved parameter/return types for visual measure/arrange/paint/hitTest, Point queries, Window/Block/Container/Page/Mount/Task/Event/Subscription methods and ObjectList.at. Signature definitions are traced managed edges. Parameters fail before dispatch; final results delegated to source/native functions must satisfy all pending native return contracts, with rooted definitions and the same frame/instruction budgets. Wrong returns release scoped results but do not undo earlier writes. CallEffect ReadOnly allows result allocation; Mutating/External calls are rejected before invocation during read-only execution. Existing heap barriers still apply, and this does not sandbox trusted native I/O. CallType unions preserve every branch definition. Page.open accepts Window or nil; page.window returns Window or nil; Block.on accepts Bool or String for its optional phase, while phase names retain domain validation. Mount relation queries are nullable, and bounds() is a real Bounds object usable by Point.inside. Native union metadata does not add Endor union syntax. Source method overrides now enforce parameter contravariance, return covariance and accepted-count preservation at class creation/method replacement, with call-time rechecks for dynamic annotation names. Ancestor replacement checks overriding descendants atomically. Unknown forward names may defer until invocation; known incompatibilities reject before effects. Native effects may only shrink; source effects remain unknown and runtime read-only barriers still apply. See examples/method-contracts.endor. Constructors/other API coverage, trait type/effect requirements and static effect inference remain pending. Unknown legacy metadata remains unknown. See examples/visual-protocols.endor and examples/layout-negotiation.endor.
|
||||
Native CallSignature checks resolved parameter/return types for visual measure/arrange/paint/hitTest, Point queries, Window/Block/Container/Page/Mount/Task/Event/Subscription methods and ObjectList.at. Signature definitions are traced managed edges. Parameters fail before dispatch; final results delegated to source/native functions must satisfy all pending native return contracts, with rooted definitions and the same frame/instruction budgets. Wrong returns release scoped results but do not undo earlier writes. CallEffect ReadOnly allows result allocation; Mutating/External calls are rejected before invocation during read-only execution. Existing heap barriers still apply, and this does not sandbox trusted native I/O. CallType unions preserve every branch definition. Page.open accepts Window or nil; page.window returns Window or nil; Block.on accepts Bool or String for its optional phase, while phase names retain domain validation. Mount relation queries are nullable, and bounds() is a real Bounds object usable by Point.inside. Native union metadata does not add Endor union syntax. Source method overrides now enforce parameter contravariance, return covariance and accepted-count preservation at class creation/method replacement, with call-time rechecks for dynamic annotation names. Ancestor replacement checks overriding descendants atomically. Unknown forward names may defer until invocation; known incompatibilities reject before effects. Native effects may only shrink; source effects remain unknown and runtime read-only barriers still apply. See examples/method-contracts.endor. Constructors/other API coverage and static source effect inference remain pending. Unknown legacy metadata remains unknown. See examples/visual-protocols.endor and examples/layout-negotiation.endor.
|
||||
|
||||
Trait definitions Visual, EventTarget, Children and Presentable are managed nominal capabilities. ui.implement(type,capability) explicitly declares an implementation after required-method/positional-arity checks; ui.implements(type,capability) and ui.supports(value,capability) query it. Block declares Visual/EventTarget; ContainerBlock declares Children, inherited by Page. Same-name methods alone never declare an implementation. Source subclass construction and host method replacement validate inherited/affected descendant contracts. Source/native positional intervals are checked, and missing native arity metadata prevents a capability declaration; source parameter/return annotations are checked at invocation. Trait type/effect compatibility and formal trait syntax remain pending. EventTarget requires canonical on/dispatch/onEvent arities 3/2/1 after self; native optional convenience forms remain.
|
||||
Trait definitions Visual, EventTarget, Children and Presentable are managed nominal capabilities. ui.implement(type,capability) explicitly declares an implementation after required-method/positional-arity/type/known-native-effect checks; ui.implements(type,capability) and ui.supports(value,capability) query it. Block declares Visual/EventTarget; ContainerBlock declares Children, inherited by Page. Same-name methods alone never declare an implementation. Source subclass construction and host method replacement validate inherited/affected descendant contracts. Source/native positional intervals are checked, and missing native arity metadata prevents a capability declaration; source parameter/return annotations are checked at invocation. These capabilities use typed signatures: registration checks parameter contravariance, return covariance and known native effects. Actual calls recheck dynamic names and final results across delegation, with rooted return definitions. Explicit typed method annotations remain checked even if a different host disables global source checks; concrete implementations keep wider inputs and optional convenience forms. Source static effects and formal trait syntax remain pending. EventTarget requires canonical on/dispatch/onEvent arities 3/2/1 after self; native optional convenience forms remain.
|
||||
|
||||
For a plain object explicitly implementing Presentable, present(self, window: Window): Block is invoked by ui.present(value) or ui.open(value), using the current managed Window and the same VM budget. The result must be an actual Block. Blocks pass through directly; unregistered values retain the summary fallback. Source views retain their business object via managed fields/callbacks/bindings, as in examples/presentable.endor. Viewing function definitions does not itself execute them. Rendering methods still run read-only with nominal result checks.
|
||||
|
||||
|
||||
@@ -3837,6 +3837,60 @@ page.render(block)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn presentable_type_contracts_reject_before_registration_or_body_effects() {
|
||||
let mut session = ReplSession::new(232).unwrap();
|
||||
session.execute("marker = ui.state(0)", "app.main").unwrap();
|
||||
for (name, method) in [
|
||||
(
|
||||
"WrongParameter",
|
||||
"function present(self: WrongParameter, window: Point): Block { marker.increment() return TextBlock(\"bad\") }",
|
||||
),
|
||||
(
|
||||
"WrongResult",
|
||||
"function present(self: WrongResult, window: Window): Number { marker.increment() return 7 }",
|
||||
),
|
||||
] {
|
||||
let input = format!("class {name} {{ {method} }} ui.implement({name}, Presentable)");
|
||||
let error = session
|
||||
.execute(&input, "app.main")
|
||||
.err()
|
||||
.expect("incompatible typed capability");
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("trait Presentable method present"),
|
||||
"{error:#}"
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute(&format!("ui.implements({name}, Presentable)"), "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"false"
|
||||
);
|
||||
assert_eq!(
|
||||
session.execute("marker.value", "app.main").unwrap().value,
|
||||
"0"
|
||||
);
|
||||
}
|
||||
session.execute(r#"
|
||||
class Good {
|
||||
function present(self: Good, window: Object): TextBlock { return TextBlock("typed") }
|
||||
}
|
||||
ui.implement(Good, Presentable)
|
||||
view = ui.present(Good())
|
||||
"#, "app.main").unwrap();
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("ui.isInstance(view, TextBlock)", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"true"
|
||||
);
|
||||
assert!(!session.is_faulted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn presentable_dispatch_preserves_source_identity_and_reactive_display() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
|
||||
+42
-13
@@ -1,5 +1,8 @@
|
||||
//! Host capability definitions over Aster's explicit managed trait relations.
|
||||
use endor_core::{MethodRequirement, ObjectRef, Value, Vm, VmError};
|
||||
use endor_core::{
|
||||
AnnotationType, CallArity, CallEffect, CallSignature, ObjectRef, TypedMethodRequirement, Value,
|
||||
Vm, VmError,
|
||||
};
|
||||
|
||||
pub fn install(
|
||||
vm: &mut Vm,
|
||||
@@ -38,22 +41,48 @@ pub fn install(
|
||||
),
|
||||
("Presentable", vec![("present", 1)], None),
|
||||
] {
|
||||
let requirements = methods
|
||||
.into_iter()
|
||||
.map(|(name, parameters)| MethodRequirement {
|
||||
name: name.into(),
|
||||
parameters,
|
||||
})
|
||||
.collect();
|
||||
let capability = vm.new_trait(name, requirements)?;
|
||||
let owner_definition = if let Some(owner) = owner {
|
||||
let Value::Object(definition) = vm.get_attr(ui, owner)? else {
|
||||
return Err(VmError::InvalidArgument("missing protocol owner"));
|
||||
};
|
||||
Some(definition)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut requirements = Vec::new();
|
||||
for (method, parameters) in methods {
|
||||
let mut signature = if let Some(owner) = owner_definition {
|
||||
let function = vm
|
||||
.object_store()
|
||||
.lookup_method(owner, method)?
|
||||
.ok_or(VmError::InvalidArgument("missing protocol method"))?;
|
||||
vm.object_store()
|
||||
.native_signature(function)?
|
||||
.ok_or(VmError::InvalidArgument(
|
||||
"protocol method lacks native types",
|
||||
))?
|
||||
} else {
|
||||
let window = crate::ui_bridge::desktop_type(vm.object_store(), "Window", desktop)?;
|
||||
let block = crate::ui_bridge::desktop_type(vm.object_store(), "Block", desktop)?;
|
||||
CallSignature::exact(
|
||||
vec![AnnotationType::Any, AnnotationType::Nominal(window)],
|
||||
AnnotationType::Nominal(block),
|
||||
CallEffect::External,
|
||||
)
|
||||
};
|
||||
signature.arity = CallArity::exact(parameters + 1);
|
||||
signature.parameters[0] = AnnotationType::Any.into();
|
||||
requirements.push(TypedMethodRequirement {
|
||||
name: method.into(),
|
||||
signature,
|
||||
});
|
||||
}
|
||||
let capability = vm.new_typed_trait(name, requirements)?;
|
||||
roots.push(capability);
|
||||
vm.attach_type(capability, trait_type)?;
|
||||
vm.set_attr(ui, name, Value::Object(capability))?;
|
||||
vm.dict_set(types, Value::Text(name.into()), Value::Object(capability))?;
|
||||
if let Some(owner) = owner {
|
||||
let Value::Object(owner) = vm.get_attr(ui, owner)? else {
|
||||
return Err(VmError::InvalidArgument("missing protocol owner"));
|
||||
};
|
||||
if let Some(owner) = owner_definition {
|
||||
vm.implement_trait(owner, capability)?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user