Skip to content

locate_graphic_protocolのライフタイムをOS本の説明にあわせた#33

Open
y-yu wants to merge 2 commits intohikalium:mainfrom
y-yu:same-lifetime-parameter-locate_graphic_protocol
Open

locate_graphic_protocolのライフタイムをOS本の説明にあわせた#33
y-yu wants to merge 2 commits intohikalium:mainfrom
y-yu:same-lifetime-parameter-locate_graphic_protocol

Conversation

@y-yu
Copy link
Copy Markdown

@y-yu y-yu commented Jun 1, 2025

概要

  • [作って学ぶ]OSのしくみⅠの64ページで、locate_graphic_protocolのライフタイムについて下記のように解説されている
    • 実際にはこの関数のシグネチャ(型定義)より、このポインタのライフタイムは、引数として渡しているEfiSystemTable の参照が持つライフタイムと同じになるとコンパイラによって推論されます1

  • 注34にある仕様書ではないが、The Rust Programming Languageの説明をまとめるとこの 👇 ようになると考えられる
    1. 引数にある参照は別々のライフタイムになるので、&EfiSystemTableには'aとは別のライフタイムパラメーターがわりあてられる
    2. 入力にライフタイムパラメーターがある場合はそれが返り値にも割り当てされるが、今回はEfiGraphicsOutputProtocolのライフタイムは明示的にライフタイムパラメーター'aが割り当てされていた
  • したがってこれまでのlocate_graphic_protocolは下記のように引数と返り値で異なるライフタイムパラメーターが割り当てされていたと考えられる
    pub fn locate_graphic_protocol<'a, 'b>(
        efi_system_table: Pin<&'b EfiSystemTable>,
    ) -> Result<&'a EfiGraphicsOutputProtocol<'a>> {
  • 下記のコミットまでは引数efi_system_tableも返り値も同じライフタイムパラメーター'aが用いられていたので、リファクタリングの際に意図せず異なるライフタイムパラメーターになってしまったと判断し、本を正としたライフタイムパラメーターに修正した

Footnotes

  1. https://doc.rust-lang.org/reference/lifetime-elision.html

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant