Skip to content

Conversation

@jonasstrehle
Copy link
Member

@jonasstrehle jonasstrehle commented Nov 14, 2025

This PR adds support for interfaces for DATEX types.

// type definition
type User = {
    name: text,
    age: integer/u8
};

// generic interface definition
interface Human {
    // "static"
    can_vote(age: integer) -> boolean;
    
    // self references
    is_adult(&self) -> boolean;
    is_senior(&self) -> boolean;
    
    // mut self reference
    hurt(&mut self) -> void;
    
    // self type
    kill(self) -> void;

    // default implementation (shall we allow that?)
    get_name(&self) -> text (
        "X Æ A-XII"
    )
}

// impl for concrete type
User implements Human {
    can_vote(age: integer) -> boolean (
       age >= 18
    )
    is_adult(&self) -> boolean (
        self.name is not "peter pan"
    )
    hurt(&mut self) -> void (
       self.age += 10
    )
    kill(self) -> void ()
};
// type definition
type User = {
    name: text,
    age: integer/u8
};

// anonymous "interface"
interface for User {
     is_ugly(&self) -> boolean (
        return self.age < 42
     )
}

// or 
interface X {
   is_ugly(&self) -> boolean;
}
type User = {
    name: text,
    age: integer/u8
} implements X;
  •  Implement draft / proposal into grammar
    • Interface parsing
    • Generics
    • Type extends
  • Implement precompiler
  • Implement type inference
  • Implement compiler
  • Implement runtime / execution
  • Implement DIF

@jonasstrehle jonasstrehle added this to the Future milestone Nov 14, 2025
@jonasstrehle jonasstrehle changed the base branch from main to release/0.0.7 November 14, 2025 18:38
@github-actions
Copy link

🐰 Bencher Report

Branchfeat/interfaces
Testbedubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
dxb to json/test1.json📈 view plot
🚷 view threshold
67.98 µs
(+5.15%)Baseline: 64.65 µs
69.55 µs
(97.73%)
dxb to json/test2.json📈 view plot
🚷 view threshold
13,379.00 µs
(+0.53%)Baseline: 13,308.14 µs
13,741.69 µs
(97.36%)
dxb to json/test3.json📈 view plot
🚷 view threshold
143,460.00 µs
(+0.38%)Baseline: 142,920.00 µs
147,939.99 µs
(96.97%)
dxb to runtime value/test1.json📈 view plot
🚷 view threshold
62.03 µs
(+52.25%)Baseline: 40.74 µs
68.18 µs
(90.98%)
dxb to runtime value/test2.json📈 view plot
🚷 view threshold
15,169.00 µs
(+37.81%)Baseline: 11,007.57 µs
16,502.01 µs
(91.92%)
dxb to runtime value/test3.json📈 view plot
🚷 view threshold
169,800.00 µs
(+73.43%)Baseline: 97,907.57 µs
190,292.76 µs
(89.23%)
json to dxb/test1.json📈 view plot
🚷 view threshold
8,329.20 µs
(+378.79%)Baseline: 1,739.62 µs
10,194.16 µs
(81.71%)
json to dxb/test2.json📈 view plot
🚷 view threshold
8,718,800.00 µs
(+519.60%)Baseline: 1,407,165.71 µs
10,787,919.98 µs
(80.82%)
json to dxb/test3.json📈 view plot
🚷 view threshold
50,589,000.00 µs
(+470.45%)Baseline: 8,868,214.29 µs
62,395,542.45 µs
(81.08%)
json to runtime value datex auto static detection/test1.json📈 view plot
🚷 view threshold
8,515.90 µs
(+380.07%)Baseline: 1,773.89 µs
10,423.84 µs
(81.70%)
json to runtime value datex auto static detection/test2.json📈 view plot
🚷 view threshold
8,837,500.00 µs
(+518.35%)Baseline: 1,429,210.00 µs
10,933,974.22 µs
(80.83%)
json to runtime value datex auto static detection/test3.json📈 view plot
🚷 view threshold
50,799,000.00 µs
(+466.92%)Baseline: 8,960,557.14 µs
62,638,862.10 µs
(81.10%)
json to runtime value datex forced static/test1.json📈 view plot
🚷 view threshold
8,148.00 µs
(+375.02%)Baseline: 1,715.29 µs
9,968.40 µs
(81.74%)
json to runtime value datex forced static/test2.json📈 view plot
🚷 view threshold
8,603,000.00 µs
(+517.71%)Baseline: 1,392,732.86 µs
10,643,435.62 µs
(80.83%)
json to runtime value datex forced static/test3.json📈 view plot
🚷 view threshold
49,852,000.00 µs
(+467.63%)Baseline: 8,782,514.29 µs
61,474,240.03 µs
(81.09%)
json to runtime value datex/test1.json📈 view plot
🚷 view threshold
8,432.60 µs
(+377.39%)Baseline: 1,766.41 µs
10,319.07 µs
(81.72%)
json to runtime value datex/test2.json📈 view plot
🚷 view threshold
8,883,900.00 µs
(+517.36%)Baseline: 1,439,012.86 µs
10,990,732.41 µs
(80.83%)
json to runtime value datex/test3.json📈 view plot
🚷 view threshold
50,837,000.00 µs
(+465.77%)Baseline: 8,985,400.00 µs
62,680,570.71 µs
(81.10%)
json to runtime value json_syntax/test1.json📈 view plot
🚷 view threshold
20.77 µs
(+2.79%)Baseline: 20.21 µs
21.37 µs
(97.19%)
json to runtime value json_syntax/test2.json📈 view plot
🚷 view threshold
6,366.60 µs
(-2.51%)Baseline: 6,530.20 µs
7,001.35 µs
(90.93%)
json to runtime value json_syntax/test3.json📈 view plot
🚷 view threshold
66,239.00 µs
(-18.88%)Baseline: 81,658.14 µs
101,569.35 µs
(65.22%)
json to runtime value serde_json/test1.json📈 view plot
🚷 view threshold
6.35 µs
(+0.82%)Baseline: 6.30 µs
6.55 µs
(97.05%)
json to runtime value serde_json/test2.json📈 view plot
🚷 view threshold
2,179.70 µs
(+1.61%)Baseline: 2,145.10 µs
2,204.56 µs
(98.87%)
json to runtime value serde_json/test3.json📈 view plot
🚷 view threshold
15,312.00 µs
(-6.03%)Baseline: 16,294.57 µs
18,303.71 µs
(83.66%)
runtime init📈 view plot
🚷 view threshold
31.83 µs
(-77.00%)Baseline: 138.40 µs
1,198.66 µs
(2.66%)
runtime value to dxb/test1.json📈 view plot
🚷 view threshold
6.58 µs
(+74.67%)Baseline: 3.77 µs
7.37 µs
(89.20%)
runtime value to dxb/test2.json📈 view plot
🚷 view threshold
1,863.80 µs
(+85.03%)Baseline: 1,007.31 µs
2,106.24 µs
(88.49%)
runtime value to dxb/test3.json📈 view plot
🚷 view threshold
20,823.00 µs
(+99.76%)Baseline: 10,424.07 µs
23,799.17 µs
(87.49%)
runtime value to json datex/test1.json📈 view plot
🚷 view threshold
75.08 µs
(+8.39%)Baseline: 69.27 µs
77.28 µs
(97.15%)
runtime value to json datex/test2.json📈 view plot
🚷 view threshold
15,475.00 µs
(+6.98%)Baseline: 14,465.86 µs
15,852.19 µs
(97.62%)
runtime value to json datex/test3.json📈 view plot
🚷 view threshold
169,000.00 µs
(+8.30%)Baseline: 156,041.43 µs
173,474.42 µs
(97.42%)
runtime value to json json_syntax/test1.json📈 view plot
🚷 view threshold
11.10 µs
(+2.82%)Baseline: 10.79 µs
11.28 µs
(98.38%)
runtime value to json json_syntax/test2.json📈 view plot
🚷 view threshold
4,689.50 µs
(+2.50%)Baseline: 4,575.09 µs
4,784.25 µs
(98.02%)
runtime value to json json_syntax/test3.json📈 view plot
🚷 view threshold
67,507.00 µs
(+5.01%)Baseline: 64,287.86 µs
72,020.55 µs
(93.73%)
runtime value to json serde_json/test1.json📈 view plot
🚷 view threshold
3.60 µs
(+18.79%)Baseline: 3.03 µs
3.86 µs
(93.47%)
runtime value to json serde_json/test2.json📈 view plot
🚷 view threshold
1,358.20 µs
(+30.27%)Baseline: 1,042.58 µs
1,479.94 µs
(91.77%)
runtime value to json serde_json/test3.json📈 view plot
🚷 view threshold
15,953.00 µs
(+46.19%)Baseline: 10,912.27 µs
17,710.64 µs
(90.08%)
🐰 View full continuous benchmarking report in Bencher

@jonasstrehle
Copy link
Member Author

type X = {
   age: integer/u8,
   name: text;
};

interface Human: X {
   is_ugly(&self) -> boolean {
      self.age > 18
   }
   is_cool(&self) -> boolean {
};

interface SuperHuman: Human {
   fly(&self) -> void;
};

type User = {
   name: string;
   age: integer/u8;
} implements SuperHuman;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants