Skip to content

Introduce mixin declaration to interface - #2996

Merged
dalance merged 1 commit into
veryl-lang:masterfrom
taichi-ishitani:mixin_interface
Jul 16, 2026
Merged

Introduce mixin declaration to interface#2996
dalance merged 1 commit into
veryl-lang:masterfrom
taichi-ishitani:mixin_interface

Conversation

@taichi-ishitani

Copy link
Copy Markdown
Contributor

Close #1212

Adds interface mixin via a new mixin declaration. Inside an interface, mixin <interface>; mixes in the members (variables, functions, and modports) of another interface; the mixed-in members are expanded into the interface as if they were declared directly.

Syntax

mixin is an interface declaration item:

interface InterfaceC {
    mixin InterfaceA;
    mixin InterfaceB;

    // additional members of the interface
}

Generic arguments can be passed to a mixed-in interface:

interface InterfaceC::<W: u32> {
    mixin InterfaceA::<W>;

    // ...
}

Restrictions on a mixed-in interface

A mixed-in interface must satisfy all of the following; otherwise an InvalidMixin error is reported:

  • It must be an interface, not a proto interface.
  • It must not have parameters (generic parameters are allowed).
  • It must not itself mix in other interfaces (nested mixin is not supported yet).
  • Its member names must not conflict with the interface's own members or with the other mixed-in interfaces' members.

Generated SystemVerilog

The mixed-in members are expanded inline into the interface. Given:

package DataPkg::<W: u32> {
    type Data = logic<W>;
}

interface Req::<W: u32> {
    import DataPkg::<W>::*;
    var command: Data;
    modport mp_req {
        command: output,
    }
}

interface Rsp {
    var status: logic;
    modport mp_rsp {
        status: input,
    }
}

interface Bus::<W: u32> {
    mixin Req::<W>;
    mixin Rsp;

    modport mp {
        ..same(mp_req, mp_rsp)
    }
}

Bus is emitted with the mixed-in members expanded (names simplified for readability):

interface Bus__W;
    // mixed in from Req
    DataPkg__W::Data command;
    modport mp_req (output command);

    // mixed in from Rsp
    logic status;
    modport mp_rsp (input status);

    // the interface's own member
    modport mp (
        output command,
        input  status
    );
endinterface

Notes:

  • A member referenced through a mixed-in interface's import is emitted in package-qualified form (e.g. DataPkg__W::Data) instead of merging the import statements. This avoids conflicts when mixed-in interfaces import same-named symbols from different packages.
  • Generic arguments passed to a mixed-in interface are propagated into the expanded members.

@taichi-ishitani
taichi-ishitani requested a review from dalance July 13, 2026 05:41
@codspeed-hq

codspeed-hq Bot commented Jul 13, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 8 untouched benchmarks


Comparing taichi-ishitani:mixin_interface (75500ce) with master (48df938)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (75500ce) during the generation of this report, so 48df938 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@taichi-ishitani
taichi-ishitani marked this pull request as draft July 13, 2026 07:14
@taichi-ishitani
taichi-ishitani force-pushed the mixin_interface branch 2 times, most recently from f423303 to 3bdd303 Compare July 13, 2026 08:02
@taichi-ishitani
taichi-ishitani marked this pull request as ready for review July 13, 2026 08:06
@taichi-ishitani
taichi-ishitani force-pushed the mixin_interface branch 6 times, most recently from bf23d71 to 9ac90b8 Compare July 14, 2026 01:58
@dalance dalance added the enhancement New feature or request label Jul 14, 2026
@taichi-ishitani
taichi-ishitani force-pushed the mixin_interface branch 2 times, most recently from 3f5942e to e49fcf5 Compare July 14, 2026 04:20
@taichi-ishitani
taichi-ishitani marked this pull request as draft July 14, 2026 05:14
@taichi-ishitani
taichi-ishitani marked this pull request as ready for review July 14, 2026 07:05
@taichi-ishitani
taichi-ishitani force-pushed the mixin_interface branch 2 times, most recently from 1b24caa to fcb32ae Compare July 14, 2026 21:08
@taichi-ishitani
taichi-ishitani marked this pull request as draft July 15, 2026 01:10
@taichi-ishitani
taichi-ishitani marked this pull request as ready for review July 15, 2026 02:12
@taichi-ishitani
taichi-ishitani marked this pull request as draft July 15, 2026 02:19
@taichi-ishitani
taichi-ishitani force-pushed the mixin_interface branch 3 times, most recently from 8941e44 to 59c24e4 Compare July 15, 2026 06:40
@taichi-ishitani
taichi-ishitani marked this pull request as ready for review July 15, 2026 06:51
@dalance

dalance commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

The whole changes look good.
Could you add a snapshot test for InvalidMixin error?

Comment thread crates/analyzer/src/symbol_table.rs Outdated
use msb::check_msb;
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
use std::collections::HashSet;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use crate::HashSet instead of std?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to crate::HashSet.

@taichi-ishitani

Copy link
Copy Markdown
Contributor Author

The whole changes look good. Could you add a snapshot test for InvalidMixin error?

I added snapshot tests for InvalidMixin error.

@taichi-ishitani
taichi-ishitani force-pushed the mixin_interface branch 3 times, most recently from fea81be to 8136af8 Compare July 16, 2026 03:00
@dalance
dalance merged commit 4201dd3 into veryl-lang:master Jul 16, 2026
20 checks passed
@taichi-ishitani
taichi-ishitani deleted the mixin_interface branch July 16, 2026 03:46
@dalance dalance added this to the v0.20.3 milestone Jul 22, 2026
@dalance dalance mentioned this pull request Jul 27, 2026
45 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature to share implementation

2 participants