Rustc Reading Club
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 2022-01-06 ## Today's plan: Pernosco! [Pernosco link](https://is.gd/PVheub) [Link at visit_item call](https://is.gd/OTxgnr) Example program: ```rust fn f() { g(); // Since there are no local variables in scope yet, this resolves to the item. let g = || {}; // "the local variable" fn g() {} // "the item" g(); // This resolves to the local variable `g` since it shadows the item. } fn main() {} ``` Command line: ```bash > RUSTC_LOG=rustc_resolve rustc +rust-0-stage1 ~/tmp/example.rs ``` Compiler `config.toml`: ```shell= # Includes one of the default files in src/bootstrap/defaults profile = "compiler" changelog-seen = 2 [rust] debug = true debuginfo-level-rustc = 2 ``` ### AST for the example * fn f -- https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/index.html * block * list of statements -- [statementkind](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.StatementKind.html) * statementkind::expr -- `g()` * statementkind::local -- `let g = ` * statementkind::item -- g * statementkind::expr -- g() ## Pattern for this time * Pernosco walk through: 15 minutes * Read through the `visit_item` of `f`, which resolves the body * Pass 1: Examine first `g()` * * Pass 2: Examine second `g()` * 10 minutes reading * 5 minutes **take notes** * 20 minutes of chat ## Pernosco notes * See the log in upper left * Go to log and hit Ctrl-F and then type "resolving item" * "Occurrences of regex" window will pop up, you can jump to points in the log * This will find the point that the body of each item is resolved * Go over to the stack, scroll to the bottom, and then scroll back UP until you see some code like `resolve_item` * You should see: ``` fn resolve_item(&mut self, item: &'ast Item) { let name = item.ident.name; debug!("(resolving item) resolving {} ({:?})", name, item.kind); ``` Other useful things: * If you go to the "Toolbox" you can add views like... * Local variables-- see the values of local variables * Callees-- see which functions are called ## Note-taking While you read, take notes however you prefer. You can use this hackmd but you can also use paper or your brain. At the end, we will take 5 minutes to leave some notes (in a section tagged with your handle) **in this hackmd** for others to persue/read. Note that while I don't plan to publish these notes, the hackmd is public and reachable by anyone who knows the url, so be polite. We'll read them over and then I'll highlight particular people to expand on what they wrote. ### Your name here ### nikomatsakis * Links * [visit_fn](https://is.gd/j3ZqJU) -- walking the function body * place where `g` is resolved the first time: [link](https://pernos.co/debug/7LJwklruo9BcakpR9BmhaA/index.html#f{m[BNk,AeQ_,t[Ag,Ebpi_,f{e[BNk,AdI_,s{afv4NqlAA,bUQ,uEgi5aQ,oEgrIHw___,v[{wz00,v[{f'list',q'stdouterr',p{_,xAS4y_,{f'container',q'stack',p{_,xAYag___,{wt1I,v[{f'source',q'source',p{_,xAUZU_,{f'list',q'callees',p{_,xa/s_,{f'container',q'locals',p{_,x2Lo____/) * Observation * a great place to start is to find the logs Comparing first and second call to `resolve_path`: * Second call terminates [here](https://pernos.co/debug/7LJwklruo9BcakpR9BmhaA/index.html#f{m[BQc,Akc_,t[Ag,Ebpi_,f{e[BQc,Af0_,s{afv4NqlAA,bUQ,uEgi5aQ,oEgjZSA___,v[{wz00,v[{f'list',q'stdouterr',p{_,xqmI_,{f'container',q'stack',p{_,x3D0_,{f'list',q'explainer',p{'explainFocus'{'data'{'producer'{'subrange'{'producer'{'memory'{'addressSpace'{'execs'Ag,'task'{'serial'AQ,'tid'Ebpb__,'ranges'[{'end'fv4ABP65,'start'fv4ABP6U____,'subrange'{'start'Aw,'end'BA___,'renderer''utf8'_,'frame'.,'moment'{'event'BQQ,'instr'AQ_,'node'AQ,'tuid'{'serial'Ag,'tid'Ebpi__,'focusSelector''output'_,xAYag___,{wt1I,v[{f'source',q'source',p{_,xw8w_,{f'list',q'callees',p{_,xQMk_,{f'container',q'locals',p{_,xggk____/) * `resolve_ident_in_lexical_scope` * eventually records resolution [here](https://pernos.co/debug/7LJwklruo9BcakpR9BmhaA/index.html#f{m[BQs,Afg_,t[Ag,Ebpi_,f{e[BQc,Af0_,s{afv4NqlAA,bUQ,uEgi5aQ,oEgjZSA___,v[{wz00,v[{f'list',q'stdouterr',p{_,xqmI_,{f'container',q'stack',p{_,x3D0_,{f'list',q'explainer',p{'explainFocus'{'data'{'producer'{'subrange'{'producer'{'memory'{'addressSpace'{'execs'Ag,'task'{'serial'AQ,'tid'Ebpb__,'ranges'[{'end'fv4ABP65,'start'fv4ABP6U____,'subrange'{'start'Aw,'end'BA___,'renderer''utf8'_,'frame'.,'moment'{'event'BQQ,'instr'AQ_,'node'AQ,'tuid'{'serial'Ag,'tid'Ebpi__,'focusSelector''output'_,xAYag___,{wt1I,v[{f'source',q'source',p{_,xw8w_,{f'list',q'callees',p{_,xQMk_,{f'container',q'locals',p{_,xggk____/) * first call kind of does the same thing ([link](https://pernos.co/debug/7LJwklruo9BcakpR9BmhaA/index.html#f{m[BN8,BZw_,t[Ag,Ebpi_,f{e[BN0,Af0_,s{afv4NqlAA,bUQ,uEgi5aQ,oEgjZSA___,v[{wz00,v[{f'list',q'stdouterr',p{_,xqmI_,{f'container',q'stack',p{_,x3D0_,{f'list',q'explainer',p{'explainFocus'{'data'{'producer'{'subrange'{'producer'{'memory'{'addressSpace'{'execs'Ag,'task'{'serial'AQ,'tid'Ebpb__,'ranges'[{'end'fv4ABP65,'start'fv4ABP6U____,'subrange'{'start'BQ,'end'Bg___,'renderer''utf8'_,'frame'.,'moment'{'event'BNo,'instr'AQ_,'node'AQ,'tuid'{'serial'Ag,'tid'Ebpi__,'focusSelector''output'_,xAYag___,{wt1I,v[{f'source',q'source',p{_,xw8w_,{f'list',q'callees',p{_,xQMk_,{f'container',q'locals',p{_,xggk_,{f'list',q'file-search',p{'file''Stdouterr','regex''resolve_path.*ident:3A%20g'_,xAYag____/)), but it winds up returning an item * so the difference is all in the way the ribs are setup Pernosco dataflow view did not help me :) [Ribs created here](https://pernos.co/debug/7LJwklruo9BcakpR9BmhaA/index.html#f{m[BPk,AcU_,t[Ag,Ebpi_,f{e[BPc,A0Y_,s{afv4NqlAA,bUQ,uEWBgHA,oEWCNHg___,v[{wz00,v[{f'list',q'stdouterr',p{_,xVTE_,{f'container',q'stack',p{_,xbh4___,{wt1I,v[{f'source',q'source',p{_,xw80_,{f'container',q'locals',p{_,xggk____/) [Block map and anonymous module seemed interesting](https://is.gd/m8H83Q) ### Sean Chen There's something akin to JavaScript hoisting going on in the example code. The nested `fn g() {}` declaration is hoisted to the top of the function body. The first `g()` call resolves to this hoisted nested function declaration. The `let g = || {}` closure definition then shadows the `fn g()` declaration. The second `g()` call resolves then to the closure definition. ### doc - Just need more time with the tool. - I'm getting a bit of a feel by experimenting, but reaching the goal is unlikely. - I'm not sure I even understand the goal. - I need the remedial version of this session. - My head hurts. ### metajack [Link to walk](https://pernos.co/debug/7LJwklruo9BcakpR9BmhaA/index.html#f{m[BM8,BiQ_,t[Ag,Ebpi_,f{e[BM8,Bhs_,s{afv4NqlAA,bUQ,uEcZcaw,oEcoDXg___/) - resolve_block() - resolve_expr() - ExprKind::Call - smart_resolve_path - why does smart_resolve_path happen? late.rs:2334 is next line executed? not highlighted (walk_expr) - what does the parse tree look like? - PathResult or a Binding. first g resolves to PathResult(PathResult::NonModule(partial_res)) - stuck again on line 2335 - the path is resolved by smart_resolve_path. expr is empty after that so nothing to do - record_partial_res is where it records the answer ### selectiveduplicate - `walk_item` function walks through `Item` nodes - `Item` kinds: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/enum.ItemKind.html - calls the corresponding `visit` method (for example, for `ItemKind::ExternCrate`, call `visitor.visit_name`) - `walk_list` macro is called (what does it do) - Still need some getting-used-to with pernosco - My goal was to understand what's going on inside `walk_item` and `resolve_item`. ## next time ### bit of a structure emerging... * we will first read deeply into a function + an example * record logs you are interested in * then use pernosco to explore it in action * come up with some question(s) that you want to see answered * then these can ideally turn into questions in the code

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully