diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 000000000..f17311098 --- /dev/null +++ b/.nojekyll @@ -0,0 +1 @@ +This file makes sure that Github Pages doesn't process mdBook's output. diff --git a/404.html b/404.html new file mode 100644 index 000000000..d8a0389af --- /dev/null +++ b/404.html @@ -0,0 +1,191 @@ + + + + + + Page not found - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Document not found (404)

+

This URL is invalid, sorry. Please use the navigation bar or search to continue.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/CNAME b/CNAME new file mode 100644 index 000000000..a59cd86cd --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +rustc-dev-guide.rust-lang.org diff --git a/FontAwesome/css/font-awesome.css b/FontAwesome/css/font-awesome.css new file mode 100644 index 000000000..540440ce8 --- /dev/null +++ b/FontAwesome/css/font-awesome.css @@ -0,0 +1,4 @@ +/*! + * Font Awesome 4.7.0 by @davegandy - http://fontawesome.io - @fontawesome + * License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License) + */@font-face{font-family:'FontAwesome';src:url('../fonts/fontawesome-webfont.eot?v=4.7.0');src:url('../fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'),url('../fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'),url('../fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'),url('../fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'),url('../fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');font-weight:normal;font-style:normal}.fa{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.fa-lg{font-size:1.33333333em;line-height:.75em;vertical-align:-15%}.fa-2x{font-size:2em}.fa-3x{font-size:3em}.fa-4x{font-size:4em}.fa-5x{font-size:5em}.fa-fw{width:1.28571429em;text-align:center}.fa-ul{padding-left:0;margin-left:2.14285714em;list-style-type:none}.fa-ul>li{position:relative}.fa-li{position:absolute;left:-2.14285714em;width:2.14285714em;top:.14285714em;text-align:center}.fa-li.fa-lg{left:-1.85714286em}.fa-border{padding:.2em .25em .15em;border:solid .08em #eee;border-radius:.1em}.fa-pull-left{float:left}.fa-pull-right{float:right}.fa.fa-pull-left{margin-right:.3em}.fa.fa-pull-right{margin-left:.3em}.pull-right{float:right}.pull-left{float:left}.fa.pull-left{margin-right:.3em}.fa.pull-right{margin-left:.3em}.fa-spin{-webkit-animation:fa-spin 2s infinite linear;animation:fa-spin 2s infinite linear}.fa-pulse{-webkit-animation:fa-spin 1s infinite steps(8);animation:fa-spin 1s infinite steps(8)}@-webkit-keyframes fa-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@keyframes fa-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(359deg);transform:rotate(359deg)}}.fa-rotate-90{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=1)";-webkit-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg)}.fa-rotate-180{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=2)";-webkit-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg)}.fa-rotate-270{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=3)";-webkit-transform:rotate(270deg);-ms-transform:rotate(270deg);transform:rotate(270deg)}.fa-flip-horizontal{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1)";-webkit-transform:scale(-1, 1);-ms-transform:scale(-1, 1);transform:scale(-1, 1)}.fa-flip-vertical{-ms-filter:"progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)";-webkit-transform:scale(1, -1);-ms-transform:scale(1, -1);transform:scale(1, -1)}:root .fa-rotate-90,:root .fa-rotate-180,:root .fa-rotate-270,:root .fa-flip-horizontal,:root .fa-flip-vertical{filter:none}.fa-stack{position:relative;display:inline-block;width:2em;height:2em;line-height:2em;vertical-align:middle}.fa-stack-1x,.fa-stack-2x{position:absolute;left:0;width:100%;text-align:center}.fa-stack-1x{line-height:inherit}.fa-stack-2x{font-size:2em}.fa-inverse{color:#fff}.fa-glass:before{content:"\f000"}.fa-music:before{content:"\f001"}.fa-search:before{content:"\f002"}.fa-envelope-o:before{content:"\f003"}.fa-heart:before{content:"\f004"}.fa-star:before{content:"\f005"}.fa-star-o:before{content:"\f006"}.fa-user:before{content:"\f007"}.fa-film:before{content:"\f008"}.fa-th-large:before{content:"\f009"}.fa-th:before{content:"\f00a"}.fa-th-list:before{content:"\f00b"}.fa-check:before{content:"\f00c"}.fa-remove:before,.fa-close:before,.fa-times:before{content:"\f00d"}.fa-search-plus:before{content:"\f00e"}.fa-search-minus:before{content:"\f010"}.fa-power-off:before{content:"\f011"}.fa-signal:before{content:"\f012"}.fa-gear:before,.fa-cog:before{content:"\f013"}.fa-trash-o:before{content:"\f014"}.fa-home:before{content:"\f015"}.fa-file-o:before{content:"\f016"}.fa-clock-o:before{content:"\f017"}.fa-road:before{content:"\f018"}.fa-download:before{content:"\f019"}.fa-arrow-circle-o-down:before{content:"\f01a"}.fa-arrow-circle-o-up:before{content:"\f01b"}.fa-inbox:before{content:"\f01c"}.fa-play-circle-o:before{content:"\f01d"}.fa-rotate-right:before,.fa-repeat:before{content:"\f01e"}.fa-refresh:before{content:"\f021"}.fa-list-alt:before{content:"\f022"}.fa-lock:before{content:"\f023"}.fa-flag:before{content:"\f024"}.fa-headphones:before{content:"\f025"}.fa-volume-off:before{content:"\f026"}.fa-volume-down:before{content:"\f027"}.fa-volume-up:before{content:"\f028"}.fa-qrcode:before{content:"\f029"}.fa-barcode:before{content:"\f02a"}.fa-tag:before{content:"\f02b"}.fa-tags:before{content:"\f02c"}.fa-book:before{content:"\f02d"}.fa-bookmark:before{content:"\f02e"}.fa-print:before{content:"\f02f"}.fa-camera:before{content:"\f030"}.fa-font:before{content:"\f031"}.fa-bold:before{content:"\f032"}.fa-italic:before{content:"\f033"}.fa-text-height:before{content:"\f034"}.fa-text-width:before{content:"\f035"}.fa-align-left:before{content:"\f036"}.fa-align-center:before{content:"\f037"}.fa-align-right:before{content:"\f038"}.fa-align-justify:before{content:"\f039"}.fa-list:before{content:"\f03a"}.fa-dedent:before,.fa-outdent:before{content:"\f03b"}.fa-indent:before{content:"\f03c"}.fa-video-camera:before{content:"\f03d"}.fa-photo:before,.fa-image:before,.fa-picture-o:before{content:"\f03e"}.fa-pencil:before{content:"\f040"}.fa-map-marker:before{content:"\f041"}.fa-adjust:before{content:"\f042"}.fa-tint:before{content:"\f043"}.fa-edit:before,.fa-pencil-square-o:before{content:"\f044"}.fa-share-square-o:before{content:"\f045"}.fa-check-square-o:before{content:"\f046"}.fa-arrows:before{content:"\f047"}.fa-step-backward:before{content:"\f048"}.fa-fast-backward:before{content:"\f049"}.fa-backward:before{content:"\f04a"}.fa-play:before{content:"\f04b"}.fa-pause:before{content:"\f04c"}.fa-stop:before{content:"\f04d"}.fa-forward:before{content:"\f04e"}.fa-fast-forward:before{content:"\f050"}.fa-step-forward:before{content:"\f051"}.fa-eject:before{content:"\f052"}.fa-chevron-left:before{content:"\f053"}.fa-chevron-right:before{content:"\f054"}.fa-plus-circle:before{content:"\f055"}.fa-minus-circle:before{content:"\f056"}.fa-times-circle:before{content:"\f057"}.fa-check-circle:before{content:"\f058"}.fa-question-circle:before{content:"\f059"}.fa-info-circle:before{content:"\f05a"}.fa-crosshairs:before{content:"\f05b"}.fa-times-circle-o:before{content:"\f05c"}.fa-check-circle-o:before{content:"\f05d"}.fa-ban:before{content:"\f05e"}.fa-arrow-left:before{content:"\f060"}.fa-arrow-right:before{content:"\f061"}.fa-arrow-up:before{content:"\f062"}.fa-arrow-down:before{content:"\f063"}.fa-mail-forward:before,.fa-share:before{content:"\f064"}.fa-expand:before{content:"\f065"}.fa-compress:before{content:"\f066"}.fa-plus:before{content:"\f067"}.fa-minus:before{content:"\f068"}.fa-asterisk:before{content:"\f069"}.fa-exclamation-circle:before{content:"\f06a"}.fa-gift:before{content:"\f06b"}.fa-leaf:before{content:"\f06c"}.fa-fire:before{content:"\f06d"}.fa-eye:before{content:"\f06e"}.fa-eye-slash:before{content:"\f070"}.fa-warning:before,.fa-exclamation-triangle:before{content:"\f071"}.fa-plane:before{content:"\f072"}.fa-calendar:before{content:"\f073"}.fa-random:before{content:"\f074"}.fa-comment:before{content:"\f075"}.fa-magnet:before{content:"\f076"}.fa-chevron-up:before{content:"\f077"}.fa-chevron-down:before{content:"\f078"}.fa-retweet:before{content:"\f079"}.fa-shopping-cart:before{content:"\f07a"}.fa-folder:before{content:"\f07b"}.fa-folder-open:before{content:"\f07c"}.fa-arrows-v:before{content:"\f07d"}.fa-arrows-h:before{content:"\f07e"}.fa-bar-chart-o:before,.fa-bar-chart:before{content:"\f080"}.fa-twitter-square:before{content:"\f081"}.fa-facebook-square:before{content:"\f082"}.fa-camera-retro:before{content:"\f083"}.fa-key:before{content:"\f084"}.fa-gears:before,.fa-cogs:before{content:"\f085"}.fa-comments:before{content:"\f086"}.fa-thumbs-o-up:before{content:"\f087"}.fa-thumbs-o-down:before{content:"\f088"}.fa-star-half:before{content:"\f089"}.fa-heart-o:before{content:"\f08a"}.fa-sign-out:before{content:"\f08b"}.fa-linkedin-square:before{content:"\f08c"}.fa-thumb-tack:before{content:"\f08d"}.fa-external-link:before{content:"\f08e"}.fa-sign-in:before{content:"\f090"}.fa-trophy:before{content:"\f091"}.fa-github-square:before{content:"\f092"}.fa-upload:before{content:"\f093"}.fa-lemon-o:before{content:"\f094"}.fa-phone:before{content:"\f095"}.fa-square-o:before{content:"\f096"}.fa-bookmark-o:before{content:"\f097"}.fa-phone-square:before{content:"\f098"}.fa-twitter:before{content:"\f099"}.fa-facebook-f:before,.fa-facebook:before{content:"\f09a"}.fa-github:before{content:"\f09b"}.fa-unlock:before{content:"\f09c"}.fa-credit-card:before{content:"\f09d"}.fa-feed:before,.fa-rss:before{content:"\f09e"}.fa-hdd-o:before{content:"\f0a0"}.fa-bullhorn:before{content:"\f0a1"}.fa-bell:before{content:"\f0f3"}.fa-certificate:before{content:"\f0a3"}.fa-hand-o-right:before{content:"\f0a4"}.fa-hand-o-left:before{content:"\f0a5"}.fa-hand-o-up:before{content:"\f0a6"}.fa-hand-o-down:before{content:"\f0a7"}.fa-arrow-circle-left:before{content:"\f0a8"}.fa-arrow-circle-right:before{content:"\f0a9"}.fa-arrow-circle-up:before{content:"\f0aa"}.fa-arrow-circle-down:before{content:"\f0ab"}.fa-globe:before{content:"\f0ac"}.fa-wrench:before{content:"\f0ad"}.fa-tasks:before{content:"\f0ae"}.fa-filter:before{content:"\f0b0"}.fa-briefcase:before{content:"\f0b1"}.fa-arrows-alt:before{content:"\f0b2"}.fa-group:before,.fa-users:before{content:"\f0c0"}.fa-chain:before,.fa-link:before{content:"\f0c1"}.fa-cloud:before{content:"\f0c2"}.fa-flask:before{content:"\f0c3"}.fa-cut:before,.fa-scissors:before{content:"\f0c4"}.fa-copy:before,.fa-files-o:before{content:"\f0c5"}.fa-paperclip:before{content:"\f0c6"}.fa-save:before,.fa-floppy-o:before{content:"\f0c7"}.fa-square:before{content:"\f0c8"}.fa-navicon:before,.fa-reorder:before,.fa-bars:before{content:"\f0c9"}.fa-list-ul:before{content:"\f0ca"}.fa-list-ol:before{content:"\f0cb"}.fa-strikethrough:before{content:"\f0cc"}.fa-underline:before{content:"\f0cd"}.fa-table:before{content:"\f0ce"}.fa-magic:before{content:"\f0d0"}.fa-truck:before{content:"\f0d1"}.fa-pinterest:before{content:"\f0d2"}.fa-pinterest-square:before{content:"\f0d3"}.fa-google-plus-square:before{content:"\f0d4"}.fa-google-plus:before{content:"\f0d5"}.fa-money:before{content:"\f0d6"}.fa-caret-down:before{content:"\f0d7"}.fa-caret-up:before{content:"\f0d8"}.fa-caret-left:before{content:"\f0d9"}.fa-caret-right:before{content:"\f0da"}.fa-columns:before{content:"\f0db"}.fa-unsorted:before,.fa-sort:before{content:"\f0dc"}.fa-sort-down:before,.fa-sort-desc:before{content:"\f0dd"}.fa-sort-up:before,.fa-sort-asc:before{content:"\f0de"}.fa-envelope:before{content:"\f0e0"}.fa-linkedin:before{content:"\f0e1"}.fa-rotate-left:before,.fa-undo:before{content:"\f0e2"}.fa-legal:before,.fa-gavel:before{content:"\f0e3"}.fa-dashboard:before,.fa-tachometer:before{content:"\f0e4"}.fa-comment-o:before{content:"\f0e5"}.fa-comments-o:before{content:"\f0e6"}.fa-flash:before,.fa-bolt:before{content:"\f0e7"}.fa-sitemap:before{content:"\f0e8"}.fa-umbrella:before{content:"\f0e9"}.fa-paste:before,.fa-clipboard:before{content:"\f0ea"}.fa-lightbulb-o:before{content:"\f0eb"}.fa-exchange:before{content:"\f0ec"}.fa-cloud-download:before{content:"\f0ed"}.fa-cloud-upload:before{content:"\f0ee"}.fa-user-md:before{content:"\f0f0"}.fa-stethoscope:before{content:"\f0f1"}.fa-suitcase:before{content:"\f0f2"}.fa-bell-o:before{content:"\f0a2"}.fa-coffee:before{content:"\f0f4"}.fa-cutlery:before{content:"\f0f5"}.fa-file-text-o:before{content:"\f0f6"}.fa-building-o:before{content:"\f0f7"}.fa-hospital-o:before{content:"\f0f8"}.fa-ambulance:before{content:"\f0f9"}.fa-medkit:before{content:"\f0fa"}.fa-fighter-jet:before{content:"\f0fb"}.fa-beer:before{content:"\f0fc"}.fa-h-square:before{content:"\f0fd"}.fa-plus-square:before{content:"\f0fe"}.fa-angle-double-left:before{content:"\f100"}.fa-angle-double-right:before{content:"\f101"}.fa-angle-double-up:before{content:"\f102"}.fa-angle-double-down:before{content:"\f103"}.fa-angle-left:before{content:"\f104"}.fa-angle-right:before{content:"\f105"}.fa-angle-up:before{content:"\f106"}.fa-angle-down:before{content:"\f107"}.fa-desktop:before{content:"\f108"}.fa-laptop:before{content:"\f109"}.fa-tablet:before{content:"\f10a"}.fa-mobile-phone:before,.fa-mobile:before{content:"\f10b"}.fa-circle-o:before{content:"\f10c"}.fa-quote-left:before{content:"\f10d"}.fa-quote-right:before{content:"\f10e"}.fa-spinner:before{content:"\f110"}.fa-circle:before{content:"\f111"}.fa-mail-reply:before,.fa-reply:before{content:"\f112"}.fa-github-alt:before{content:"\f113"}.fa-folder-o:before{content:"\f114"}.fa-folder-open-o:before{content:"\f115"}.fa-smile-o:before{content:"\f118"}.fa-frown-o:before{content:"\f119"}.fa-meh-o:before{content:"\f11a"}.fa-gamepad:before{content:"\f11b"}.fa-keyboard-o:before{content:"\f11c"}.fa-flag-o:before{content:"\f11d"}.fa-flag-checkered:before{content:"\f11e"}.fa-terminal:before{content:"\f120"}.fa-code:before{content:"\f121"}.fa-mail-reply-all:before,.fa-reply-all:before{content:"\f122"}.fa-star-half-empty:before,.fa-star-half-full:before,.fa-star-half-o:before{content:"\f123"}.fa-location-arrow:before{content:"\f124"}.fa-crop:before{content:"\f125"}.fa-code-fork:before{content:"\f126"}.fa-unlink:before,.fa-chain-broken:before{content:"\f127"}.fa-question:before{content:"\f128"}.fa-info:before{content:"\f129"}.fa-exclamation:before{content:"\f12a"}.fa-superscript:before{content:"\f12b"}.fa-subscript:before{content:"\f12c"}.fa-eraser:before{content:"\f12d"}.fa-puzzle-piece:before{content:"\f12e"}.fa-microphone:before{content:"\f130"}.fa-microphone-slash:before{content:"\f131"}.fa-shield:before{content:"\f132"}.fa-calendar-o:before{content:"\f133"}.fa-fire-extinguisher:before{content:"\f134"}.fa-rocket:before{content:"\f135"}.fa-maxcdn:before{content:"\f136"}.fa-chevron-circle-left:before{content:"\f137"}.fa-chevron-circle-right:before{content:"\f138"}.fa-chevron-circle-up:before{content:"\f139"}.fa-chevron-circle-down:before{content:"\f13a"}.fa-html5:before{content:"\f13b"}.fa-css3:before{content:"\f13c"}.fa-anchor:before{content:"\f13d"}.fa-unlock-alt:before{content:"\f13e"}.fa-bullseye:before{content:"\f140"}.fa-ellipsis-h:before{content:"\f141"}.fa-ellipsis-v:before{content:"\f142"}.fa-rss-square:before{content:"\f143"}.fa-play-circle:before{content:"\f144"}.fa-ticket:before{content:"\f145"}.fa-minus-square:before{content:"\f146"}.fa-minus-square-o:before{content:"\f147"}.fa-level-up:before{content:"\f148"}.fa-level-down:before{content:"\f149"}.fa-check-square:before{content:"\f14a"}.fa-pencil-square:before{content:"\f14b"}.fa-external-link-square:before{content:"\f14c"}.fa-share-square:before{content:"\f14d"}.fa-compass:before{content:"\f14e"}.fa-toggle-down:before,.fa-caret-square-o-down:before{content:"\f150"}.fa-toggle-up:before,.fa-caret-square-o-up:before{content:"\f151"}.fa-toggle-right:before,.fa-caret-square-o-right:before{content:"\f152"}.fa-euro:before,.fa-eur:before{content:"\f153"}.fa-gbp:before{content:"\f154"}.fa-dollar:before,.fa-usd:before{content:"\f155"}.fa-rupee:before,.fa-inr:before{content:"\f156"}.fa-cny:before,.fa-rmb:before,.fa-yen:before,.fa-jpy:before{content:"\f157"}.fa-ruble:before,.fa-rouble:before,.fa-rub:before{content:"\f158"}.fa-won:before,.fa-krw:before{content:"\f159"}.fa-bitcoin:before,.fa-btc:before{content:"\f15a"}.fa-file:before{content:"\f15b"}.fa-file-text:before{content:"\f15c"}.fa-sort-alpha-asc:before{content:"\f15d"}.fa-sort-alpha-desc:before{content:"\f15e"}.fa-sort-amount-asc:before{content:"\f160"}.fa-sort-amount-desc:before{content:"\f161"}.fa-sort-numeric-asc:before{content:"\f162"}.fa-sort-numeric-desc:before{content:"\f163"}.fa-thumbs-up:before{content:"\f164"}.fa-thumbs-down:before{content:"\f165"}.fa-youtube-square:before{content:"\f166"}.fa-youtube:before{content:"\f167"}.fa-xing:before{content:"\f168"}.fa-xing-square:before{content:"\f169"}.fa-youtube-play:before{content:"\f16a"}.fa-dropbox:before{content:"\f16b"}.fa-stack-overflow:before{content:"\f16c"}.fa-instagram:before{content:"\f16d"}.fa-flickr:before{content:"\f16e"}.fa-adn:before{content:"\f170"}.fa-bitbucket:before{content:"\f171"}.fa-bitbucket-square:before{content:"\f172"}.fa-tumblr:before{content:"\f173"}.fa-tumblr-square:before{content:"\f174"}.fa-long-arrow-down:before{content:"\f175"}.fa-long-arrow-up:before{content:"\f176"}.fa-long-arrow-left:before{content:"\f177"}.fa-long-arrow-right:before{content:"\f178"}.fa-apple:before{content:"\f179"}.fa-windows:before{content:"\f17a"}.fa-android:before{content:"\f17b"}.fa-linux:before{content:"\f17c"}.fa-dribbble:before{content:"\f17d"}.fa-skype:before{content:"\f17e"}.fa-foursquare:before{content:"\f180"}.fa-trello:before{content:"\f181"}.fa-female:before{content:"\f182"}.fa-male:before{content:"\f183"}.fa-gittip:before,.fa-gratipay:before{content:"\f184"}.fa-sun-o:before{content:"\f185"}.fa-moon-o:before{content:"\f186"}.fa-archive:before{content:"\f187"}.fa-bug:before{content:"\f188"}.fa-vk:before{content:"\f189"}.fa-weibo:before{content:"\f18a"}.fa-renren:before{content:"\f18b"}.fa-pagelines:before{content:"\f18c"}.fa-stack-exchange:before{content:"\f18d"}.fa-arrow-circle-o-right:before{content:"\f18e"}.fa-arrow-circle-o-left:before{content:"\f190"}.fa-toggle-left:before,.fa-caret-square-o-left:before{content:"\f191"}.fa-dot-circle-o:before{content:"\f192"}.fa-wheelchair:before{content:"\f193"}.fa-vimeo-square:before{content:"\f194"}.fa-turkish-lira:before,.fa-try:before{content:"\f195"}.fa-plus-square-o:before{content:"\f196"}.fa-space-shuttle:before{content:"\f197"}.fa-slack:before{content:"\f198"}.fa-envelope-square:before{content:"\f199"}.fa-wordpress:before{content:"\f19a"}.fa-openid:before{content:"\f19b"}.fa-institution:before,.fa-bank:before,.fa-university:before{content:"\f19c"}.fa-mortar-board:before,.fa-graduation-cap:before{content:"\f19d"}.fa-yahoo:before{content:"\f19e"}.fa-google:before{content:"\f1a0"}.fa-reddit:before{content:"\f1a1"}.fa-reddit-square:before{content:"\f1a2"}.fa-stumbleupon-circle:before{content:"\f1a3"}.fa-stumbleupon:before{content:"\f1a4"}.fa-delicious:before{content:"\f1a5"}.fa-digg:before{content:"\f1a6"}.fa-pied-piper-pp:before{content:"\f1a7"}.fa-pied-piper-alt:before{content:"\f1a8"}.fa-drupal:before{content:"\f1a9"}.fa-joomla:before{content:"\f1aa"}.fa-language:before{content:"\f1ab"}.fa-fax:before{content:"\f1ac"}.fa-building:before{content:"\f1ad"}.fa-child:before{content:"\f1ae"}.fa-paw:before{content:"\f1b0"}.fa-spoon:before{content:"\f1b1"}.fa-cube:before{content:"\f1b2"}.fa-cubes:before{content:"\f1b3"}.fa-behance:before{content:"\f1b4"}.fa-behance-square:before{content:"\f1b5"}.fa-steam:before{content:"\f1b6"}.fa-steam-square:before{content:"\f1b7"}.fa-recycle:before{content:"\f1b8"}.fa-automobile:before,.fa-car:before{content:"\f1b9"}.fa-cab:before,.fa-taxi:before{content:"\f1ba"}.fa-tree:before{content:"\f1bb"}.fa-spotify:before{content:"\f1bc"}.fa-deviantart:before{content:"\f1bd"}.fa-soundcloud:before{content:"\f1be"}.fa-database:before{content:"\f1c0"}.fa-file-pdf-o:before{content:"\f1c1"}.fa-file-word-o:before{content:"\f1c2"}.fa-file-excel-o:before{content:"\f1c3"}.fa-file-powerpoint-o:before{content:"\f1c4"}.fa-file-photo-o:before,.fa-file-picture-o:before,.fa-file-image-o:before{content:"\f1c5"}.fa-file-zip-o:before,.fa-file-archive-o:before{content:"\f1c6"}.fa-file-sound-o:before,.fa-file-audio-o:before{content:"\f1c7"}.fa-file-movie-o:before,.fa-file-video-o:before{content:"\f1c8"}.fa-file-code-o:before{content:"\f1c9"}.fa-vine:before{content:"\f1ca"}.fa-codepen:before{content:"\f1cb"}.fa-jsfiddle:before{content:"\f1cc"}.fa-life-bouy:before,.fa-life-buoy:before,.fa-life-saver:before,.fa-support:before,.fa-life-ring:before{content:"\f1cd"}.fa-circle-o-notch:before{content:"\f1ce"}.fa-ra:before,.fa-resistance:before,.fa-rebel:before{content:"\f1d0"}.fa-ge:before,.fa-empire:before{content:"\f1d1"}.fa-git-square:before{content:"\f1d2"}.fa-git:before{content:"\f1d3"}.fa-y-combinator-square:before,.fa-yc-square:before,.fa-hacker-news:before{content:"\f1d4"}.fa-tencent-weibo:before{content:"\f1d5"}.fa-qq:before{content:"\f1d6"}.fa-wechat:before,.fa-weixin:before{content:"\f1d7"}.fa-send:before,.fa-paper-plane:before{content:"\f1d8"}.fa-send-o:before,.fa-paper-plane-o:before{content:"\f1d9"}.fa-history:before{content:"\f1da"}.fa-circle-thin:before{content:"\f1db"}.fa-header:before{content:"\f1dc"}.fa-paragraph:before{content:"\f1dd"}.fa-sliders:before{content:"\f1de"}.fa-share-alt:before{content:"\f1e0"}.fa-share-alt-square:before{content:"\f1e1"}.fa-bomb:before{content:"\f1e2"}.fa-soccer-ball-o:before,.fa-futbol-o:before{content:"\f1e3"}.fa-tty:before{content:"\f1e4"}.fa-binoculars:before{content:"\f1e5"}.fa-plug:before{content:"\f1e6"}.fa-slideshare:before{content:"\f1e7"}.fa-twitch:before{content:"\f1e8"}.fa-yelp:before{content:"\f1e9"}.fa-newspaper-o:before{content:"\f1ea"}.fa-wifi:before{content:"\f1eb"}.fa-calculator:before{content:"\f1ec"}.fa-paypal:before{content:"\f1ed"}.fa-google-wallet:before{content:"\f1ee"}.fa-cc-visa:before{content:"\f1f0"}.fa-cc-mastercard:before{content:"\f1f1"}.fa-cc-discover:before{content:"\f1f2"}.fa-cc-amex:before{content:"\f1f3"}.fa-cc-paypal:before{content:"\f1f4"}.fa-cc-stripe:before{content:"\f1f5"}.fa-bell-slash:before{content:"\f1f6"}.fa-bell-slash-o:before{content:"\f1f7"}.fa-trash:before{content:"\f1f8"}.fa-copyright:before{content:"\f1f9"}.fa-at:before{content:"\f1fa"}.fa-eyedropper:before{content:"\f1fb"}.fa-paint-brush:before{content:"\f1fc"}.fa-birthday-cake:before{content:"\f1fd"}.fa-area-chart:before{content:"\f1fe"}.fa-pie-chart:before{content:"\f200"}.fa-line-chart:before{content:"\f201"}.fa-lastfm:before{content:"\f202"}.fa-lastfm-square:before{content:"\f203"}.fa-toggle-off:before{content:"\f204"}.fa-toggle-on:before{content:"\f205"}.fa-bicycle:before{content:"\f206"}.fa-bus:before{content:"\f207"}.fa-ioxhost:before{content:"\f208"}.fa-angellist:before{content:"\f209"}.fa-cc:before{content:"\f20a"}.fa-shekel:before,.fa-sheqel:before,.fa-ils:before{content:"\f20b"}.fa-meanpath:before{content:"\f20c"}.fa-buysellads:before{content:"\f20d"}.fa-connectdevelop:before{content:"\f20e"}.fa-dashcube:before{content:"\f210"}.fa-forumbee:before{content:"\f211"}.fa-leanpub:before{content:"\f212"}.fa-sellsy:before{content:"\f213"}.fa-shirtsinbulk:before{content:"\f214"}.fa-simplybuilt:before{content:"\f215"}.fa-skyatlas:before{content:"\f216"}.fa-cart-plus:before{content:"\f217"}.fa-cart-arrow-down:before{content:"\f218"}.fa-diamond:before{content:"\f219"}.fa-ship:before{content:"\f21a"}.fa-user-secret:before{content:"\f21b"}.fa-motorcycle:before{content:"\f21c"}.fa-street-view:before{content:"\f21d"}.fa-heartbeat:before{content:"\f21e"}.fa-venus:before{content:"\f221"}.fa-mars:before{content:"\f222"}.fa-mercury:before{content:"\f223"}.fa-intersex:before,.fa-transgender:before{content:"\f224"}.fa-transgender-alt:before{content:"\f225"}.fa-venus-double:before{content:"\f226"}.fa-mars-double:before{content:"\f227"}.fa-venus-mars:before{content:"\f228"}.fa-mars-stroke:before{content:"\f229"}.fa-mars-stroke-v:before{content:"\f22a"}.fa-mars-stroke-h:before{content:"\f22b"}.fa-neuter:before{content:"\f22c"}.fa-genderless:before{content:"\f22d"}.fa-facebook-official:before{content:"\f230"}.fa-pinterest-p:before{content:"\f231"}.fa-whatsapp:before{content:"\f232"}.fa-server:before{content:"\f233"}.fa-user-plus:before{content:"\f234"}.fa-user-times:before{content:"\f235"}.fa-hotel:before,.fa-bed:before{content:"\f236"}.fa-viacoin:before{content:"\f237"}.fa-train:before{content:"\f238"}.fa-subway:before{content:"\f239"}.fa-medium:before{content:"\f23a"}.fa-yc:before,.fa-y-combinator:before{content:"\f23b"}.fa-optin-monster:before{content:"\f23c"}.fa-opencart:before{content:"\f23d"}.fa-expeditedssl:before{content:"\f23e"}.fa-battery-4:before,.fa-battery:before,.fa-battery-full:before{content:"\f240"}.fa-battery-3:before,.fa-battery-three-quarters:before{content:"\f241"}.fa-battery-2:before,.fa-battery-half:before{content:"\f242"}.fa-battery-1:before,.fa-battery-quarter:before{content:"\f243"}.fa-battery-0:before,.fa-battery-empty:before{content:"\f244"}.fa-mouse-pointer:before{content:"\f245"}.fa-i-cursor:before{content:"\f246"}.fa-object-group:before{content:"\f247"}.fa-object-ungroup:before{content:"\f248"}.fa-sticky-note:before{content:"\f249"}.fa-sticky-note-o:before{content:"\f24a"}.fa-cc-jcb:before{content:"\f24b"}.fa-cc-diners-club:before{content:"\f24c"}.fa-clone:before{content:"\f24d"}.fa-balance-scale:before{content:"\f24e"}.fa-hourglass-o:before{content:"\f250"}.fa-hourglass-1:before,.fa-hourglass-start:before{content:"\f251"}.fa-hourglass-2:before,.fa-hourglass-half:before{content:"\f252"}.fa-hourglass-3:before,.fa-hourglass-end:before{content:"\f253"}.fa-hourglass:before{content:"\f254"}.fa-hand-grab-o:before,.fa-hand-rock-o:before{content:"\f255"}.fa-hand-stop-o:before,.fa-hand-paper-o:before{content:"\f256"}.fa-hand-scissors-o:before{content:"\f257"}.fa-hand-lizard-o:before{content:"\f258"}.fa-hand-spock-o:before{content:"\f259"}.fa-hand-pointer-o:before{content:"\f25a"}.fa-hand-peace-o:before{content:"\f25b"}.fa-trademark:before{content:"\f25c"}.fa-registered:before{content:"\f25d"}.fa-creative-commons:before{content:"\f25e"}.fa-gg:before{content:"\f260"}.fa-gg-circle:before{content:"\f261"}.fa-tripadvisor:before{content:"\f262"}.fa-odnoklassniki:before{content:"\f263"}.fa-odnoklassniki-square:before{content:"\f264"}.fa-get-pocket:before{content:"\f265"}.fa-wikipedia-w:before{content:"\f266"}.fa-safari:before{content:"\f267"}.fa-chrome:before{content:"\f268"}.fa-firefox:before{content:"\f269"}.fa-opera:before{content:"\f26a"}.fa-internet-explorer:before{content:"\f26b"}.fa-tv:before,.fa-television:before{content:"\f26c"}.fa-contao:before{content:"\f26d"}.fa-500px:before{content:"\f26e"}.fa-amazon:before{content:"\f270"}.fa-calendar-plus-o:before{content:"\f271"}.fa-calendar-minus-o:before{content:"\f272"}.fa-calendar-times-o:before{content:"\f273"}.fa-calendar-check-o:before{content:"\f274"}.fa-industry:before{content:"\f275"}.fa-map-pin:before{content:"\f276"}.fa-map-signs:before{content:"\f277"}.fa-map-o:before{content:"\f278"}.fa-map:before{content:"\f279"}.fa-commenting:before{content:"\f27a"}.fa-commenting-o:before{content:"\f27b"}.fa-houzz:before{content:"\f27c"}.fa-vimeo:before{content:"\f27d"}.fa-black-tie:before{content:"\f27e"}.fa-fonticons:before{content:"\f280"}.fa-reddit-alien:before{content:"\f281"}.fa-edge:before{content:"\f282"}.fa-credit-card-alt:before{content:"\f283"}.fa-codiepie:before{content:"\f284"}.fa-modx:before{content:"\f285"}.fa-fort-awesome:before{content:"\f286"}.fa-usb:before{content:"\f287"}.fa-product-hunt:before{content:"\f288"}.fa-mixcloud:before{content:"\f289"}.fa-scribd:before{content:"\f28a"}.fa-pause-circle:before{content:"\f28b"}.fa-pause-circle-o:before{content:"\f28c"}.fa-stop-circle:before{content:"\f28d"}.fa-stop-circle-o:before{content:"\f28e"}.fa-shopping-bag:before{content:"\f290"}.fa-shopping-basket:before{content:"\f291"}.fa-hashtag:before{content:"\f292"}.fa-bluetooth:before{content:"\f293"}.fa-bluetooth-b:before{content:"\f294"}.fa-percent:before{content:"\f295"}.fa-gitlab:before{content:"\f296"}.fa-wpbeginner:before{content:"\f297"}.fa-wpforms:before{content:"\f298"}.fa-envira:before{content:"\f299"}.fa-universal-access:before{content:"\f29a"}.fa-wheelchair-alt:before{content:"\f29b"}.fa-question-circle-o:before{content:"\f29c"}.fa-blind:before{content:"\f29d"}.fa-audio-description:before{content:"\f29e"}.fa-volume-control-phone:before{content:"\f2a0"}.fa-braille:before{content:"\f2a1"}.fa-assistive-listening-systems:before{content:"\f2a2"}.fa-asl-interpreting:before,.fa-american-sign-language-interpreting:before{content:"\f2a3"}.fa-deafness:before,.fa-hard-of-hearing:before,.fa-deaf:before{content:"\f2a4"}.fa-glide:before{content:"\f2a5"}.fa-glide-g:before{content:"\f2a6"}.fa-signing:before,.fa-sign-language:before{content:"\f2a7"}.fa-low-vision:before{content:"\f2a8"}.fa-viadeo:before{content:"\f2a9"}.fa-viadeo-square:before{content:"\f2aa"}.fa-snapchat:before{content:"\f2ab"}.fa-snapchat-ghost:before{content:"\f2ac"}.fa-snapchat-square:before{content:"\f2ad"}.fa-pied-piper:before{content:"\f2ae"}.fa-first-order:before{content:"\f2b0"}.fa-yoast:before{content:"\f2b1"}.fa-themeisle:before{content:"\f2b2"}.fa-google-plus-circle:before,.fa-google-plus-official:before{content:"\f2b3"}.fa-fa:before,.fa-font-awesome:before{content:"\f2b4"}.fa-handshake-o:before{content:"\f2b5"}.fa-envelope-open:before{content:"\f2b6"}.fa-envelope-open-o:before{content:"\f2b7"}.fa-linode:before{content:"\f2b8"}.fa-address-book:before{content:"\f2b9"}.fa-address-book-o:before{content:"\f2ba"}.fa-vcard:before,.fa-address-card:before{content:"\f2bb"}.fa-vcard-o:before,.fa-address-card-o:before{content:"\f2bc"}.fa-user-circle:before{content:"\f2bd"}.fa-user-circle-o:before{content:"\f2be"}.fa-user-o:before{content:"\f2c0"}.fa-id-badge:before{content:"\f2c1"}.fa-drivers-license:before,.fa-id-card:before{content:"\f2c2"}.fa-drivers-license-o:before,.fa-id-card-o:before{content:"\f2c3"}.fa-quora:before{content:"\f2c4"}.fa-free-code-camp:before{content:"\f2c5"}.fa-telegram:before{content:"\f2c6"}.fa-thermometer-4:before,.fa-thermometer:before,.fa-thermometer-full:before{content:"\f2c7"}.fa-thermometer-3:before,.fa-thermometer-three-quarters:before{content:"\f2c8"}.fa-thermometer-2:before,.fa-thermometer-half:before{content:"\f2c9"}.fa-thermometer-1:before,.fa-thermometer-quarter:before{content:"\f2ca"}.fa-thermometer-0:before,.fa-thermometer-empty:before{content:"\f2cb"}.fa-shower:before{content:"\f2cc"}.fa-bathtub:before,.fa-s15:before,.fa-bath:before{content:"\f2cd"}.fa-podcast:before{content:"\f2ce"}.fa-window-maximize:before{content:"\f2d0"}.fa-window-minimize:before{content:"\f2d1"}.fa-window-restore:before{content:"\f2d2"}.fa-times-rectangle:before,.fa-window-close:before{content:"\f2d3"}.fa-times-rectangle-o:before,.fa-window-close-o:before{content:"\f2d4"}.fa-bandcamp:before{content:"\f2d5"}.fa-grav:before{content:"\f2d6"}.fa-etsy:before{content:"\f2d7"}.fa-imdb:before{content:"\f2d8"}.fa-ravelry:before{content:"\f2d9"}.fa-eercast:before{content:"\f2da"}.fa-microchip:before{content:"\f2db"}.fa-snowflake-o:before{content:"\f2dc"}.fa-superpowers:before{content:"\f2dd"}.fa-wpexplorer:before{content:"\f2de"}.fa-meetup:before{content:"\f2e0"}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);border:0}.sr-only-focusable:active,.sr-only-focusable:focus{position:static;width:auto;height:auto;margin:0;overflow:visible;clip:auto} diff --git a/FontAwesome/fonts/FontAwesome.ttf b/FontAwesome/fonts/FontAwesome.ttf new file mode 100644 index 000000000..35acda2fa Binary files /dev/null and b/FontAwesome/fonts/FontAwesome.ttf differ diff --git a/FontAwesome/fonts/fontawesome-webfont.eot b/FontAwesome/fonts/fontawesome-webfont.eot new file mode 100644 index 000000000..e9f60ca95 Binary files /dev/null and b/FontAwesome/fonts/fontawesome-webfont.eot differ diff --git a/FontAwesome/fonts/fontawesome-webfont.svg b/FontAwesome/fonts/fontawesome-webfont.svg new file mode 100644 index 000000000..855c845e5 --- /dev/null +++ b/FontAwesome/fonts/fontawesome-webfont.svg @@ -0,0 +1,2671 @@ + + + + +Created by FontForge 20120731 at Mon Oct 24 17:37:40 2016 + By ,,, +Copyright Dave Gandy 2016. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FontAwesome/fonts/fontawesome-webfont.ttf b/FontAwesome/fonts/fontawesome-webfont.ttf new file mode 100644 index 000000000..35acda2fa Binary files /dev/null and b/FontAwesome/fonts/fontawesome-webfont.ttf differ diff --git a/FontAwesome/fonts/fontawesome-webfont.woff b/FontAwesome/fonts/fontawesome-webfont.woff new file mode 100644 index 000000000..400014a4b Binary files /dev/null and b/FontAwesome/fonts/fontawesome-webfont.woff differ diff --git a/FontAwesome/fonts/fontawesome-webfont.woff2 b/FontAwesome/fonts/fontawesome-webfont.woff2 new file mode 100644 index 000000000..4d13fc604 Binary files /dev/null and b/FontAwesome/fonts/fontawesome-webfont.woff2 differ diff --git a/about-this-guide.html b/about-this-guide.html new file mode 100644 index 000000000..c5daa3376 --- /dev/null +++ b/about-this-guide.html @@ -0,0 +1,275 @@ + + + + + + About this guide - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

About this guide

+

This guide is meant to help document how rustc – the Rust compiler – works, +as well as to help new contributors get involved in rustc development.

+

There are seven parts to this guide:

+
    +
  1. Building rustc: +Contains information that should be useful no matter how you are contributing, +about building, debugging, profiling, etc.
  2. +
  3. Contributing to rustc: +Contains information that should be useful no matter how you are contributing, +about procedures for contribution, using git and Github, stabilizing features, etc.
  4. +
  5. High-Level Compiler Architecture: +Discusses the high-level architecture of the compiler and stages of the compile process.
  6. +
  7. Source Code Representation: +Describes the process of taking raw source code from the user +and transforming it into various forms that the compiler can work with easily.
  8. +
  9. Analysis: +discusses the analyses that the compiler uses to check various properties of the code +and inform later stages of the compile process (e.g., type checking).
  10. +
  11. From MIR to Binaries: How linked executable machine code is generated.
  12. +
  13. Appendices at the end with useful reference information. +There are a few of these with different information, including a glossary.
  14. +
+

Constant change

+

Keep in mind that rustc is a real production-quality product, +being worked upon continuously by a sizeable set of contributors. +As such, it has its fair share of codebase churn and technical debt. +In addition, many of the ideas discussed throughout this guide are idealized designs +that are not fully realized yet. +All this makes keeping this guide completely up to date on everything very hard!

+

The Guide itself is of course open-source as well, +and the sources can be found at the GitHub repository. +If you find any mistakes in the guide, please file an issue about it. +Even better, open a PR with a correction!

+

If you do contribute to the guide, +please see the corresponding subsection on writing documentation in this guide.

+
+

“‘All conditioned things are impermanent’ — +when one sees this with wisdom, one turns away from suffering.” +The Dhammapada, verse 277

+
+

Other places to find information

+

You might also find the following sites useful:

+
    +
  • This guide contains information about how various parts of the +compiler work and how to contribute to the compiler.
  • +
  • rustc API docs -- rustdoc documentation for the compiler, devtools, and internal tools
  • +
  • Forge -- contains documentation about Rust infrastructure, team procedures, and more
  • +
  • compiler-team -- the home-base for the Rust compiler team, with description +of the team procedures, active working groups, and the team calendar.
  • +
  • std-dev-guide -- a similar guide for developing the standard library.
  • +
  • The t-compiler zulip
  • +
  • #contribute and #wg-rustup on Discord.
  • +
  • The Rust Internals forum, a place to ask questions and +discuss Rust's internals
  • +
  • The Rust reference, even though it doesn't specifically talk about +Rust's internals, is a great resource nonetheless
  • +
  • Although out of date, Tom Lee's great blog article is very helpful
  • +
  • rustaceans.org is helpful, but mostly dedicated to IRC
  • +
  • The Rust Compiler Testing Docs
  • +
  • For @bors, this cheat sheet is helpful
  • +
  • Google is always helpful when programming. +You can search all Rust documentation (the standard library, +the compiler, the books, the references, and the guides) to quickly find +information about the language and compiler.
  • +
  • You can also use Rustdoc's built-in search feature to find documentation on +types and functions within the crates you're looking at. You can also search +by type signature! For example, searching for * -> vec should find all +functions that return a Vec<T>. +Hint: Find more tips and keyboard shortcuts by typing ? on any Rustdoc +page!
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/appendix/background.html b/appendix/background.html new file mode 100644 index 000000000..d4a15edfb --- /dev/null +++ b/appendix/background.html @@ -0,0 +1,476 @@ + + + + + + Appendix A: Background topics - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Background topics

+

This section covers a numbers of common compiler terms that arise in +this guide. We try to give the general definition while providing some +Rust-specific context.

+

+

What is a control-flow graph?

+

A control-flow graph (CFG) is a common term from compilers. If you've ever +used a flow-chart, then the concept of a control-flow graph will be +pretty familiar to you. It's a representation of your program that +clearly exposes the underlying control flow.

+

A control-flow graph is structured as a set of basic blocks +connected by edges. The key idea of a basic block is that it is a set +of statements that execute "together" – that is, whenever you branch +to a basic block, you start at the first statement and then execute +all the remainder. Only at the end of the block is there the +possibility of branching to more than one place (in MIR, we call that +final statement the terminator):

+
bb0: {
+    statement0;
+    statement1;
+    statement2;
+    ...
+    terminator;
+}
+
+

Many expressions that you are used to in Rust compile down to multiple +basic blocks. For example, consider an if statement:

+
a = 1;
+if some_variable {
+    b = 1;
+} else {
+    c = 1;
+}
+d = 1;
+
+

This would compile into four basic blocks in MIR. In textual form, it looks like +this:

+
BB0: {
+    a = 1;
+    if some_variable {
+        goto BB1;
+    } else {
+        goto BB2;
+    }
+}
+
+BB1: {
+    b = 1;
+    goto BB3;
+}
+
+BB2: {
+    c = 1;
+    goto BB3;
+}
+
+BB3: {
+    d = 1;
+    ...
+}
+
+

In graphical form, it looks like this:

+
                BB0
+       +--------------------+
+       | a = 1;             |
+       +--------------------+
+             /       \
+  if some_variable   else
+           /           \
+     BB1  /             \  BB2
+    +-----------+   +-----------+
+    | b = 1;    |   | c = 1;    |
+    +-----------+   +-----------+
+            \          /
+             \        /
+              \ BB3  /
+            +----------+
+            | d = 1;   |
+            | ...      |
+            +----------+
+
+

When using a control-flow graph, a loop simply appears as a cycle in +the graph, and the break keyword translates into a path out of that +cycle.

+

+

What is a dataflow analysis?

+

Static Program Analysis by Anders Møller +and Michael I. Schwartzbach is an incredible resource!

+

Dataflow analysis is a type of static analysis that is common in many +compilers. It describes a general technique, rather than a particular analysis.

+

The basic idea is that we can walk over a control-flow graph (CFG) and +keep track of what some value could be. At the end of the walk, we might have +shown that some claim is true or not necessarily true (e.g. "this variable must +be initialized"). rustc tends to do dataflow analyses over the MIR, since MIR +is already a CFG.

+

For example, suppose we want to check that x is initialized before it is used +in this snippet:

+
fn foo() {
+    let mut x;
+
+    if some_cond {
+        x = 1;
+    }
+
+    dbg!(x);
+}
+
+

A CFG for this code might look like this:

+
 +------+
+ | Init | (A)
+ +------+
+    |   \
+    |   if some_cond
+  else    \ +-------+
+    |      \| x = 1 | (B)
+    |       +-------+
+    |      /
+ +---------+
+ | dbg!(x) | (C)
+ +---------+
+
+

We can do the dataflow analysis as follows: we will start off with a flag init +which indicates if we know x is initialized. As we walk the CFG, we will +update the flag. At the end, we can check its value.

+

So first, in block (A), the variable x is declared but not initialized, so +init = false. In block (B), we initialize the value, so we know that x is +initialized. So at the end of (B), init = true.

+

Block (C) is where things get interesting. Notice that there are two incoming +edges, one from (A) and one from (B), corresponding to whether some_cond is true or not. +But we cannot know that! It could be the case the some_cond is always true, +so that x is actually always initialized. It could also be the case that +some_cond depends on something random (e.g. the time), so x may not be +initialized. In general, we cannot know statically (due to Rice's +Theorem). So what should the value of init be in block (C)?

+

Generally, in dataflow analyses, if a block has multiple parents (like (C) in +our example), its dataflow value will be some function of all its parents (and +of course, what happens in (C)). Which function we use depends on the analysis +we are doing.

+

In this case, we want to be able to prove definitively that x must be +initialized before use. This forces us to be conservative and assume that +some_cond might be false sometimes. So our "merging function" is "and". That +is, init = true in (C) if init = true in (A) and in (B) (or if x is +initialized in (C)). But this is not the case; in particular, init = false in +(A), and x is not initialized in (C). Thus, init = false in (C); we can +report an error that "x may not be initialized before use".

+

There is definitely a lot more that can be said about dataflow analyses. There is an +extensive body of research literature on the topic, including a lot of theory. +We only discussed a forwards analysis, but backwards dataflow analysis is also +useful. For example, rather than starting from block (A) and moving forwards, +we might have started with the usage of x and moved backwards to try to find +its initialization.

+

+

What is "universally quantified"? What about "existentially quantified"?

+

In math, a predicate may be universally quantified or existentially +quantified:

+
    +
  • Universal quantification: +
      +
    • the predicate holds if it is true for all possible inputs.
    • +
    • Traditional notation: ∀x: P(x). Read as "for all x, P(x) holds".
    • +
    +
  • +
  • Existential quantification: +
      +
    • the predicate holds if there is any input where it is true, i.e., there +only has to be a single input.
    • +
    • Traditional notation: ∃x: P(x). Read as "there exists x such that P(x) holds".
    • +
    +
  • +
+

In Rust, they come up in type checking and trait solving. For example,

+
fn foo<T>()
+
+

This function claims that the function is well-typed for all types T: ∀ T: well_typed(foo).

+

Another example:

+
fn foo<'a>(_: &'a usize)
+
+

This function claims that for any lifetime 'a (determined by the +caller), it is well-typed: ∀ 'a: well_typed(foo).

+

Another example:

+
fn foo<F>()
+where for<'a> F: Fn(&'a u8)
+
+

This function claims that it is well-typed for all types F such that for all +lifetimes 'a, F: Fn(&'a u8): ∀ F: ∀ 'a: (F: Fn(&'a u8)) => well_typed(foo).

+

One more example:

+
fn foo(_: dyn Debug)
+
+

This function claims that there exists some type T that implements Debug +such that the function is well-typed: ∃ T: (T: Debug) and well_typed(foo).

+

+

What is a de Bruijn Index?

+

De Bruijn indices are a way of representing, using only integers, +which variables are bound in which binders. They were originally invented for +use in lambda calculus evaluation (see this Wikipedia article for +more). In rustc, we use de Bruijn indices to represent generic types.

+

Here is a basic example of how de Bruijn indices might be used for closures (we +don't actually do this in rustc though!):

+
|x| {
+    f(x) // de Bruijn index of `x` is 1 because `x` is bound 1 level up
+
+    |y| {
+        g(x, y) // index of `x` is 2 because it is bound 2 levels up
+                // index of `y` is 1 because it is bound 1 level up
+    }
+}
+
+

What are co- and contra-variance?

+

Check out the subtyping chapter from the +Rust Nomicon.

+

See the variance chapter of this guide for more info on how +the type checker handles variance.

+

+

What is a "free region" or a "free variable"? What about "bound region"?

+

Let's describe the concepts of free vs bound in terms of program +variables, since that's the thing we're most familiar with.

+
    +
  • Consider this expression, which creates a closure: |a, b| a + b. +Here, the a and b in a + b refer to the arguments that the closure will +be given when it is called. We say that the a and b there are bound to +the closure, and that the closure signature |a, b| is a binder for the +names a and b (because any references to a or b within refer to the +variables that it introduces).
  • +
  • Consider this expression: a + b. In this expression, a and b refer to +local variables that are defined outside of the expression. We say that +those variables appear free in the expression (i.e., they are free, +not bound (tied up)).
  • +
+

So there you have it: a variable "appears free" in some +expression/statement/whatever if it refers to something defined +outside of that expressions/statement/whatever. Equivalently, we can +then refer to the "free variables" of an expression – which is just +the set of variables that "appear free".

+

So what does this have to do with regions? Well, we can apply the +analogous concept to type and regions. For example, in the type &'a u32, 'a appears free. But in the type for<'a> fn(&'a u32), it +does not.

+

Further Reading About Compilers

+
+

Thanks to mem, scottmcm, and Levi on the official Discord for the +recommendations, and to tinaun for posting a link to a twitter thread from +Graydon Hoare +which had some more recommendations!

+

Other sources: https://gcc.gnu.org/wiki/ListOfCompilerBooks

+

If you have other suggestions, please feel free to open an issue or PR.

+
+

Books

+ +

Courses

+ +

Wikis

+ +

Misc Papers and Blog Posts

+ + +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/appendix/bibliography.html b/appendix/bibliography.html new file mode 100644 index 000000000..fadc72784 --- /dev/null +++ b/appendix/bibliography.html @@ -0,0 +1,298 @@ + + + + + + Appendix E: Bibliography - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Rust Bibliography

+

This is a reading list of material relevant to Rust. It includes prior +research that has - at one time or another - influenced the design of +Rust, as well as publications about Rust.

+

Type system

+ +

Concurrency

+ +

Others

+ +

Papers about Rust

+ + +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/appendix/code-index.html b/appendix/code-index.html new file mode 100644 index 000000000..3166d6dc3 --- /dev/null +++ b/appendix/code-index.html @@ -0,0 +1,233 @@ + + + + + + Appendix C: Code Index - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Code Index

+

rustc has a lot of important data structures. This is an attempt to give some +guidance on where to learn more about some of the key data structures of the +compiler.

+
+ + + + + + + + + + + + + + + + + + + + + + + + +
ItemKindShort descriptionChapterDeclaration
BodyIdstructOne of four types of HIR node identifiersIdentifiers in the HIRcompiler/rustc_hir/src/hir.rs
CompilerstructRepresents a compiler session and can be used to drive a compilation.The Rustc Driver and Interfacecompiler/rustc_interface/src/interface.rs
ast::CratestructA syntax-level representation of a parsed crateThe parsercompiler/rustc_ast/src/ast.rs
rustc_hir::CratestructA more abstract, compiler-friendly form of a crate's ASTThe Hircompiler/rustc_hir/src/hir.rs
DefIdstructOne of four types of HIR node identifiersIdentifiers in the HIRcompiler/rustc_hir/src/def_id.rs
DiagstructA struct for a compiler diagnostic, such as an error or lintEmitting Diagnosticscompiler/rustc_errors/src/diagnostic.rs
DocContextstructA state container used by rustdoc when crawling through a crate to gather its documentationRustdocsrc/librustdoc/core.rs
HirIdstructOne of four types of HIR node identifiersIdentifiers in the HIRcompiler/rustc_hir/src/hir_id.rs
NodeIdstructOne of four types of HIR node identifiers. Being phased outIdentifiers in the HIRcompiler/rustc_ast/src/ast.rs
PstructAn owned immutable smart pointer. By contrast, &T is not owned, and Box<T> is not immutable.Nonecompiler/rustc_ast/src/ptr.rs
ParamEnvstructInformation about generic parameters or Self, useful for working with associated or generic itemsParameter Environmentcompiler/rustc_middle/src/ty/mod.rs
ParseSessstructThis struct contains information about a parsing sessionThe parsercompiler/rustc_session/src/parse/parse.rs
QuerystructRepresents the result of query to the Compiler interface and allows stealing, borrowing, and returning the results of compiler passes.The Rustc Driver and Interfacecompiler/rustc_interface/src/queries.rs
RibstructRepresents a single scope of namesName resolutioncompiler/rustc_resolve/src/lib.rs
SessionstructThe data associated with a compilation sessionThe parser, The Rustc Driver and Interfacecompiler/rustc_session/src/session.rs
SourceFilestructPart of the SourceMap. Maps AST nodes to their source code for a single source file. Was previously called FileMapThe parsercompiler/rustc_span/src/lib.rs
SourceMapstructMaps AST nodes to their source code. It is composed of SourceFiles. Was previously called CodeMapThe parsercompiler/rustc_span/src/source_map.rs
SpanstructA location in the user's source code, used for error reporting primarilyEmitting Diagnosticscompiler/rustc_span/src/span_encoding.rs
StringReaderstructThis is the lexer used during parsing. It consumes characters from the raw source code being compiled and produces a series of tokens for use by the rest of the parserThe parsercompiler/rustc_parse/src/lexer/mod.rs
rustc_ast::token_stream::TokenStreamstructAn abstract sequence of tokens, organized into TokenTreesThe parser, Macro expansioncompiler/rustc_ast/src/tokenstream.rs
TraitDefstructThis struct contains a trait's definition with type informationThe ty modulescompiler/rustc_middle/src/ty/trait_def.rs
TraitRefstructThe combination of a trait and its input types (e.g. P0: Trait<P1...Pn>)Trait Solving: Goals and Clausescompiler/rustc_middle/src/ty/sty.rs
Ty<'tcx>structThis is the internal representation of a type used for type checkingType checkingcompiler/rustc_middle/src/ty/mod.rs
TyCtxt<'tcx>structThe "typing context". This is the central data structure in the compiler. It is the context that you use to perform all manner of queriesThe ty modulescompiler/rustc_middle/src/ty/context.rs
+
+
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/appendix/compiler-lecture.html b/appendix/compiler-lecture.html new file mode 100644 index 000000000..d28b35f04 --- /dev/null +++ b/appendix/compiler-lecture.html @@ -0,0 +1,259 @@ + + + + + + Appendix D: Compiler Lecture Series - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Compiler Lecture Series

+

These are videos where various experts explain different parts of the compiler:

+

General

+ +

Rust Analyzer

+ +

Type System

+ +

Closures

+ +

Chalk

+ +

Polonius

+ +

Miri

+ +

Async

+ +

Code Generation

+ + +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/appendix/glossary.html b/appendix/glossary.html new file mode 100644 index 000000000..839e5af05 --- /dev/null +++ b/appendix/glossary.html @@ -0,0 +1,301 @@ + + + + + + Appendix B: Glossary - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Glossary

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TermMeaning
arena, arena allocationAn arena is a large memory buffer from which other memory allocations are made. This style of allocation is called arena allocation. See this chapter for more info.
ASTThe abstract syntax tree produced by the rustc_ast crate; reflects user syntax very closely.
APITAn argument-position impl Trait. Also known as an anonymous type parameter. (see the reference).
binderA binder is a place where a variable or type is declared; for example, the <T> is a binder for the generic type parameter T in fn foo<T>(..), and |a| ... is a binder for the parameter a. See the background chapter for more.
BodyIdAn identifier that refers to a specific body (definition of a function or constant) in the crate. See the HIR chapter for more.
bound variableA bound variable is one that is declared within an expression/term. For example, the variable a is bound within the closure expression |a| a * 2. See the background chapter for more
codegenShort for code generation. The code to translate MIR into LLVM IR.
codegen unitWhen we produce LLVM IR, we group the Rust code into a number of codegen units (sometimes abbreviated as CGUs). Each of these units is processed by LLVM independently from one another, enabling parallelism. They are also the unit of incremental re-use. (see more)
completenessA technical term in type theory, it means that every type-safe program also type-checks. Having both soundness and completeness is very hard, and usually soundness is more important. (see "soundness").
control-flow graphA representation of the control-flow of a program; see the background chapter for more
CTFEShort for compile-time function evaluation, this is the ability of the compiler to evaluate const fns at compile time. This is part of the compiler's constant evaluation system. (see more)
cxWe tend to use cx as an abbreviation for context. See also tcx, infcx, etc.
ctxtWe also use ctxt as an abbreviation for context, e.g. TyCtxt. See also cx or tcx.
DAGA directed acyclic graph is used during compilation to keep track of dependencies between queries. (see more)
data-flow analysisA static analysis that figures out what properties are true at each point in the control-flow of a program; see the background chapter for more.
de Bruijn indexA technique for describing which binder a variable is bound by using only integers. It has the benefit that it is invariant under variable renaming. (see more)
DefIdAn index identifying a definition (see rustc_middle/src/hir/def_id.rs). Uniquely identifies a DefPath. See the HIR chapter for more.
discriminantThe underlying value associated with an enum variant or generator state to indicate it as "active" (but not to be confused with its "variant index"). At runtime, the discriminant of the active variant is encoded in the tag.
double pointerA pointer with additional metadata. See fat pointer for more.
drop glue(Internal) compiler-generated instructions that handle calling the destructors (Drop) for data types.
DSTShort for dynamically-sized type, this is a type for which the compiler cannot statically know the size in memory (e.g. str or [u8]). Such types don't implement Sized and cannot be allocated on the stack. They can only occur as the last field in a struct. They can only be used behind a pointer (e.g. &str or &[u8]).
early-bound lifetimeA lifetime region that is substituted at its definition site. Bound in an item's Generics and substituted/instantiated using a GenericArgs. Contrast with late-bound lifetime. (see more)
effectsRight now only means const traits and ~const bounds. (see more)
empty typeSee uninhabited type.
fat pointerA two word value carrying the address of some value, along with some further information necessary to put the value to use. Rust includes two kinds of fat pointers: references to slices, and trait objects. A reference to a slice carries the starting address of the slice and its length. A trait object carries a value's address and a pointer to the trait's implementation appropriate to that value. "Fat pointers" are also known as "wide pointers", and "double pointers".
free variableA free variable is one that is not bound within an expression or term; see the background chapter for more
genericsThe list of generic parameters defined on an item. There are three kinds of generic parameters: Type, lifetime and const parameters.
HIRThe high-level IR, created by lowering and desugaring the AST. (see more)
HirIdIdentifies a particular node in the HIR by combining a def-id with an "intra-definition offset". See the HIR chapter for more.
HIR mapThe HIR map, accessible via tcx.hir(), allows you to quickly navigate the HIR and convert between various forms of identifiers.
ICEShort for internal compiler error, this is when the compiler crashes.
ICHShort for incremental compilation hash, these are used as fingerprints for things such as HIR and crate metadata, to check if changes have been made. This is useful in incremental compilation to see if part of a crate has changed and should be recompiled.
infcxThe type inference context (InferCtxt). (see rustc_middle::infer)
inference variable, infer var When doing type, region, const inference, an inference variable is a kind of special type/region that represents what you are trying to infer. Think of X in algebra. For example, if we are trying to infer the type of a variable in a program, we create an inference variable to represent that unknown type.
internInterning refers to storing certain frequently-used constant data, such as strings, and then referring to the data by an identifier (e.g. a Symbol) rather than the data itself, to reduce memory usage and number of allocations. See this chapter for more info.
interpreterThe heart of const evaluation, running MIR code at compile time. (see more)
intrinsicIntrinsics are special functions that are implemented in the compiler itself but exposed (often unstably) to users. They do magical and dangerous things. (See std::intrinsics)
IRShort for intermediate representation, a general term in compilers. During compilation, the code is transformed from raw source (ASCII text) to various IRs. In Rust, these are primarily HIR, MIR, and LLVM IR. Each IR is well-suited for some set of computations. For example, MIR is well-suited for the borrow checker, and LLVM IR is well-suited for codegen because LLVM accepts it.
IRLO, irloSometimes used as an abbreviation for internals.rust-lang.org.
itemA kind of "definition" in the language, such as a static, const, use statement, module, struct, etc. Concretely, this corresponds to the Item type.
lang itemItems that represent concepts intrinsic to the language itself, such as special built-in traits like Sync and Send; or traits representing operations such as Add; or functions that are called by the compiler. (see more)
late-bound lifetimeA lifetime region that is substituted at its call site. Bound in a HRTB and substituted by specific functions in the compiler, such as liberate_late_bound_regions. Contrast with early-bound lifetime. (see more)
local crateThe crate currently being compiled. This is in contrast to "upstream crates" which refer to dependencies of the local crate.
LTOShort for link-time optimizations, this is a set of optimizations offered by LLVM that occur just before the final binary is linked. These include optimizations like removing functions that are never used in the final program, for example. ThinLTO is a variant of LTO that aims to be a bit more scalable and efficient, but possibly sacrifices some optimizations. You may also read issues in the Rust repo about "FatLTO", which is the loving nickname given to non-Thin LTO. LLVM documentation: here and here.
LLVM(actually not an acronym :P) an open-source compiler backend. It accepts LLVM IR and outputs native binaries. Various languages (e.g. Rust) can then implement a compiler front-end that outputs LLVM IR and use LLVM to compile to all the platforms LLVM supports.
memoizationThe process of storing the results of (pure) computations (such as pure function calls) to avoid having to repeat them in the future. This is typically a trade-off between execution speed and memory usage.
MIRThe mid-level IR that is created after type-checking for use by borrowck and codegen. (see more)
MiriA tool to detect Undefined Behavior in (unsafe) Rust code. (see more)
monomorphizationThe process of taking generic implementations of types and functions and instantiating them with concrete types. For example, in the code we might have Vec<T>, but in the final executable, we will have a copy of the Vec code for every concrete type used in the program (e.g. a copy for Vec<usize>, a copy for Vec<MyStruct>, etc).
normalizeA general term for converting to a more canonical form, but in the case of rustc typically refers to associated type normalization.
newtypeA wrapper around some other type (e.g., struct Foo(T) is a "newtype" for T). This is commonly used in Rust to give a stronger type for indices.
nicheInvalid bit patterns for a type that can be used for layout optimizations. Some types cannot have certain bit patterns. For example, the NonZero* integers or the reference &T cannot be represented by a 0 bitstring. This means the compiler can perform layout optimizations by taking advantage of the invalid "niche value". An example application for this is the Discriminant elision on Option-like enums, which allows using a type's niche as the "tag" for an enum without requiring a separate field.
NLLShort for non-lexical lifetimes, this is an extension to Rust's borrowing system to make it be based on the control-flow graph.
node-id or NodeIdAn index identifying a particular node in the AST or HIR; gradually being phased out and replaced with HirId. See the HIR chapter for more.
obligationSomething that must be proven by the trait system. (see more)
placeholderNOTE: skolemization is deprecated by placeholder a way of handling subtyping around "for-all" types (e.g., for<'a> fn(&'a u32)) as well as solving higher-ranked trait bounds (e.g., for<'a> T: Trait<'a>). See the chapter on placeholder and universes for more details.
pointUsed in the NLL analysis to refer to some particular location in the MIR; typically used to refer to a node in the control-flow graph.
polymorphizeAn optimization that avoids unnecessary monomorphisation. (see more)
projectionA general term for a "relative path", e.g. x.f is a "field projection", and T::Item is an "associated type projection".
promoted constantsConstants extracted from a function and lifted to static scope; see this section for more details.
providerThe function that executes a query. (see more)
quantifiedIn math or logic, existential and universal quantification are used to ask questions like "is there any type T for which is true?" or "is this true for all types T?"; see the background chapter for more.
queryA sub-computation during compilation. Query results can be cached in the current session or to disk for incremental compilation. (see more)
recoveryRecovery refers to handling invalid syntax during parsing (e.g. a missing comma) and continuing to parse the AST. This avoid showing spurious errors to the user (e.g. showing 'missing field' errors when the struct definition contains errors).
regionAnother term for "lifetime" often used in the literature and in the borrow checker.
ribA data structure in the name resolver that keeps track of a single scope for names. (see more)
RPITA return-position impl Trait. (see the reference).
RPITITA return-position impl Trait in trait. Unlike RPIT, this is desugared to a generic associated type (GAT). Introduced in RFC 3425. (see more)
scrutineeA scrutinee is the expression that is matched on in match expressions and similar pattern matching constructs. For example, in match x { A => 1, B => 2 }, the expression x is the scrutinee.
sessThe compiler session, which stores global data used throughout compilation
side tablesBecause the AST and HIR are immutable once created, we often carry extra information about them in the form of hashtables, indexed by the id of a particular node.
sigilLike a keyword but composed entirely of non-alphanumeric tokens. For example, & is a sigil for references.
soundnessA technical term in type theory. Roughly, if a type system is sound, then a program that type-checks is type-safe. That is, one can never (in safe rust) force a value into a variable of the wrong type. (see "completeness").
spanA location in the user's source code, used for error reporting primarily. These are like a file-name/line-number/column tuple on steroids: they carry a start/end point, and also track macro expansions and compiler desugaring. All while being packed into a few bytes (really, it's an index into a table). See the Span datatype for more.
substThe act of substituting the generic parameters inside of a type, constant expression, etc. with concrete generic arguments by supplying substs. Nowadays referred to as instantiating in the compiler.
substsThe substitutions for a given generic item (e.g. the i32, u32 in HashMap<i32, u32>). Nowadays referred to as the list of generic arguments in the compiler (but note that strictly speaking these two concepts differ, see the literature).
sysrootThe directory for build artifacts that are loaded by the compiler at runtime. (see more)
tagThe "tag" of an enum/generator encodes the discriminant of the active variant/state. Tags can either be "direct" (simply storing the discriminant in a field) or use a "niche".
TAITA type-alias impl Trait. Introduced in RFC 2515.
tcxStandard variable name for the "typing context" (TyCtxt), main data structure of the compiler. (see more)
'tcxThe lifetime of the allocation arenas used by TyCtxt. Most data interned during a compilation session will use this lifetime with the exception of HIR data which uses the 'hir lifetime. (see more)
tokenThe smallest unit of parsing. Tokens are produced after lexing (see more).
TLSThread-local storage. Variables may be defined so that each thread has its own copy (rather than all threads sharing the variable). This has some interactions with LLVM. Not all platforms support TLS.
trait reference, trait ref The name of a trait along with a suitable list of generic arguments. (see more)
transShort for translation, the code to translate MIR into LLVM IR. Renamed to codegen.
TyThe internal representation of a type. (see more)
TyCtxtThe data structure often referred to as tcx in code which provides access to session data and the query system.
UFCSShort for universal function call syntax, this is an unambiguous syntax for calling a method. Term no longer in use! Prefer fully-qualified path/syntax. (see more, see the reference)
uninhabited typeA type which has no values. This is not the same as a ZST, which has exactly 1 value. An example of an uninhabited type is enum Foo {}, which has no variants, and so, can never be created. The compiler can treat code that deals with uninhabited types as dead code, since there is no such value to be manipulated. ! (the never type) is an uninhabited type. Uninhabited types are also called empty types.
upvarA variable captured by a closure from outside the closure.
varianceDetermines how changes to a generic parameter affect subtyping; for example, if T is a subtype of U, then Vec<T> is a subtype Vec<U> because Vec is covariant in its generic parameter. See the background chapter for a more general explanation. See the variance chapter for an explanation of how type checking handles variance.
variant indexIn an enum, identifies a variant by assigning them indices starting at 0. This is purely internal and not to be confused with the "discriminant" which can be overwritten by the user (e.g. enum Bool { True = 42, False = 0 }).
well-formednessSemantically: An expression that evaluates to meaningful result. In type systems: A type related construct which follows rules of the type system.
wide pointerA pointer with additional metadata. See fat pointer for more.
ZSTZero-sized type. A type whose values have size 0 bytes. Since 2^0 = 1, such types can have exactly one value. For example, () (unit) is a ZST. struct Foo; is also a ZST. The compiler can do some nice optimizations around ZSTs.
+
+
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/appendix/humorust.html b/appendix/humorust.html new file mode 100644 index 000000000..bf86d5f76 --- /dev/null +++ b/appendix/humorust.html @@ -0,0 +1,212 @@ + + + + + + Appendix Z: HumorRust - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/asm.html b/asm.html new file mode 100644 index 000000000..238c96c75 --- /dev/null +++ b/asm.html @@ -0,0 +1,572 @@ + + + + + + Inline assembly - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Inline assembly

+ +

Overview

+

Inline assembly in rustc mostly revolves around taking an asm! macro invocation and plumbing it +through all of the compiler layers down to LLVM codegen. Throughout the various stages, an +InlineAsm generally consists of 3 components:

+
    +
  • +

    The template string, which is stored as an array of InlineAsmTemplatePiece. Each piece +represents either a literal or a placeholder for an operand (just like format strings).

    +
    #![allow(unused)]
    +fn main() {
    +pub enum InlineAsmTemplatePiece {
    +    String(String),
    +    Placeholder { operand_idx: usize, modifier: Option<char>, span: Span },
    +}
    +}
    +
    +
  • +
  • +

    The list of operands to the asm! (in, [late]out, in[late]out, sym, const). These are +represented differently at each stage of lowering, but follow a common pattern:

    +
      +
    • in, out and inout all have an associated register class (reg) or explicit register +("eax").
    • +
    • inout has 2 forms: one with a single expression that is both read from and written to, and +one with two separate expressions for the input and output parts.
    • +
    • out and inout have a late flag (lateout / inlateout) to indicate that the register +allocator is allowed to reuse an input register for this output.
    • +
    • out and the split variant of inout allow _ to be specified for an output, which means +that the output is discarded. This is used to allocate scratch registers for assembly code.
    • +
    • const refers to an anonymous constants and generally works like an inline const.
    • +
    • sym is a bit special since it only accepts a path expression, which must point to a static +or a fn.
    • +
    +
  • +
  • +

    The options set at the end of the asm! macro. The only ones that are of particular interest to +rustc are NORETURN which makes asm! return ! instead of (), and RAW which disables format +string parsing. The remaining options are mostly passed through to LLVM with little processing.

    +
    #![allow(unused)]
    +fn main() {
    +bitflags::bitflags! {
    +    pub struct InlineAsmOptions: u16 {
    +        const PURE = 1 << 0;
    +        const NOMEM = 1 << 1;
    +        const READONLY = 1 << 2;
    +        const PRESERVES_FLAGS = 1 << 3;
    +        const NORETURN = 1 << 4;
    +        const NOSTACK = 1 << 5;
    +        const ATT_SYNTAX = 1 << 6;
    +        const RAW = 1 << 7;
    +        const MAY_UNWIND = 1 << 8;
    +    }
    +}
    +}
    +
    +
  • +
+

AST

+

InlineAsm is represented as an expression in the AST:

+
#![allow(unused)]
+fn main() {
+pub struct InlineAsm {
+    pub template: Vec<InlineAsmTemplatePiece>,
+    pub template_strs: Box<[(Symbol, Option<Symbol>, Span)]>,
+    pub operands: Vec<(InlineAsmOperand, Span)>,
+    pub clobber_abi: Option<(Symbol, Span)>,
+    pub options: InlineAsmOptions,
+    pub line_spans: Vec<Span>,
+}
+
+pub enum InlineAsmRegOrRegClass {
+    Reg(Symbol),
+    RegClass(Symbol),
+}
+
+pub enum InlineAsmOperand {
+    In {
+        reg: InlineAsmRegOrRegClass,
+        expr: P<Expr>,
+    },
+    Out {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        expr: Option<P<Expr>>,
+    },
+    InOut {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        expr: P<Expr>,
+    },
+    SplitInOut {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        in_expr: P<Expr>,
+        out_expr: Option<P<Expr>>,
+    },
+    Const {
+        anon_const: AnonConst,
+    },
+    Sym {
+        expr: P<Expr>,
+    },
+}
+}
+
+

The asm! macro is implemented in rustc_builtin_macros and outputs an InlineAsm AST node. The +template string is parsed using fmt_macros, positional and named operands are resolved to +explicit operand indices. Since target information is not available to macro invocations, +validation of the registers and register classes is deferred to AST lowering.

+

HIR

+

InlineAsm is represented as an expression in the HIR:

+
#![allow(unused)]
+fn main() {
+pub struct InlineAsm<'hir> {
+    pub template: &'hir [InlineAsmTemplatePiece],
+    pub template_strs: &'hir [(Symbol, Option<Symbol>, Span)],
+    pub operands: &'hir [(InlineAsmOperand<'hir>, Span)],
+    pub options: InlineAsmOptions,
+    pub line_spans: &'hir [Span],
+}
+
+pub enum InlineAsmRegOrRegClass {
+    Reg(InlineAsmReg),
+    RegClass(InlineAsmRegClass),
+}
+
+pub enum InlineAsmOperand<'hir> {
+    In {
+        reg: InlineAsmRegOrRegClass,
+        expr: Expr<'hir>,
+    },
+    Out {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        expr: Option<Expr<'hir>>,
+    },
+    InOut {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        expr: Expr<'hir>,
+    },
+    SplitInOut {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        in_expr: Expr<'hir>,
+        out_expr: Option<Expr<'hir>>,
+    },
+    Const {
+        anon_const: AnonConst,
+    },
+    Sym {
+        expr: Expr<'hir>,
+    },
+}
+}
+
+

AST lowering is where InlineAsmRegOrRegClass is converted from Symbols to an actual register or +register class. If any modifiers are specified for a template string placeholder, these are +validated against the set allowed for that operand type. Finally, explicit registers for inputs and +outputs are checked for conflicts (same register used for different operands).

+

Type checking

+

Each register class has a whitelist of types that it may be used with. After the types of all +operands have been determined, the intrinsicck pass will check that these types are in the +whitelist. It also checks that split inout operands have compatible types and that const +operands are integers or floats. Suggestions are emitted where needed if a template modifier should +be used for an operand based on the type that was passed into it.

+

THIR

+

InlineAsm is represented as an expression in the THIR:

+
#![allow(unused)]
+fn main() {
+crate enum ExprKind<'tcx> {
+    // [..]
+    InlineAsm {
+        template: &'tcx [InlineAsmTemplatePiece],
+        operands: Box<[InlineAsmOperand<'tcx>]>,
+        options: InlineAsmOptions,
+        line_spans: &'tcx [Span],
+    },
+}
+crate enum InlineAsmOperand<'tcx> {
+    In {
+        reg: InlineAsmRegOrRegClass,
+        expr: ExprId,
+    },
+    Out {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        expr: Option<ExprId>,
+    },
+    InOut {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        expr: ExprId,
+    },
+    SplitInOut {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        in_expr: ExprId,
+        out_expr: Option<ExprId>,
+    },
+    Const {
+        value: &'tcx Const<'tcx>,
+        span: Span,
+    },
+    SymFn {
+        expr: ExprId,
+    },
+    SymStatic {
+        def_id: DefId,
+    },
+}
+}
+
+

The only significant change compared to HIR is that Sym has been lowered to either a SymFn +whose expr is a Literal ZST of the fn, or a SymStatic which points to the DefId of a +static.

+

MIR

+

InlineAsm is represented as a Terminator in the MIR:

+
#![allow(unused)]
+fn main() {
+pub enum TerminatorKind<'tcx> {
+    // [..]
+
+    /// Block ends with an inline assembly block. This is a terminator since
+    /// inline assembly is allowed to diverge.
+    InlineAsm {
+        /// The template for the inline assembly, with placeholders.
+        template: &'tcx [InlineAsmTemplatePiece],
+
+        /// The operands for the inline assembly, as `Operand`s or `Place`s.
+        operands: Vec<InlineAsmOperand<'tcx>>,
+
+        /// Miscellaneous options for the inline assembly.
+        options: InlineAsmOptions,
+
+        /// Source spans for each line of the inline assembly code. These are
+        /// used to map assembler errors back to the line in the source code.
+        line_spans: &'tcx [Span],
+
+        /// Destination block after the inline assembly returns, unless it is
+        /// diverging (InlineAsmOptions::NORETURN).
+        destination: Option<BasicBlock>,
+    },
+}
+
+pub enum InlineAsmOperand<'tcx> {
+    In {
+        reg: InlineAsmRegOrRegClass,
+        value: Operand<'tcx>,
+    },
+    Out {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        place: Option<Place<'tcx>>,
+    },
+    InOut {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        in_value: Operand<'tcx>,
+        out_place: Option<Place<'tcx>>,
+    },
+    Const {
+        value: Box<Constant<'tcx>>,
+    },
+    SymFn {
+        value: Box<Constant<'tcx>>,
+    },
+    SymStatic {
+        def_id: DefId,
+    },
+}
+}
+
+

As part of THIR lowering, InOut and SplitInOut operands are lowered to a split form with a +separate in_value and out_place.

+

Semantically, the InlineAsm terminator is similar to the Call terminator except that it has +multiple output places where a Call only has a single return place output.

+

Codegen

+

Operands are lowered one more time before being passed to LLVM codegen:

+
#![allow(unused)]
+fn main() {
+pub enum InlineAsmOperandRef<'tcx, B: BackendTypes + ?Sized> {
+    In {
+        reg: InlineAsmRegOrRegClass,
+        value: OperandRef<'tcx, B::Value>,
+    },
+    Out {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        place: Option<PlaceRef<'tcx, B::Value>>,
+    },
+    InOut {
+        reg: InlineAsmRegOrRegClass,
+        late: bool,
+        in_value: OperandRef<'tcx, B::Value>,
+        out_place: Option<PlaceRef<'tcx, B::Value>>,
+    },
+    Const {
+        string: String,
+    },
+    SymFn {
+        instance: Instance<'tcx>,
+    },
+    SymStatic {
+        def_id: DefId,
+    },
+}
+}
+
+

The operands are lowered to LLVM operands and constraint codes as follow:

+
    +
  • out and the output part of inout operands are added first, as required by LLVM. Late output +operands have a = prefix added to their constraint code, non-late output operands have a =& +prefix added to their constraint code.
  • +
  • in operands are added normally.
  • +
  • inout operands are tied to the matching output operand.
  • +
  • sym operands are passed as function pointers or pointers, using the "s" constraint.
  • +
  • const operands are formatted to a string and directly inserted in the template string.
  • +
+

The template string is converted to LLVM form:

+
    +
  • $ characters are escaped as $$.
  • +
  • const operands are converted to strings and inserted directly.
  • +
  • Placeholders are formatted as ${X:M} where X is the operand index and M is the modifier +character. Modifiers are converted from the Rust form to the LLVM form.
  • +
+

The various options are converted to clobber constraints or LLVM attributes, refer to the +RFC +for more details.

+

Note that LLVM is sometimes rather picky about what types it accepts for certain constraint codes +so we sometimes need to insert conversions to/from a supported type. See the target-specific +ISelLowering.cpp files in LLVM for details of what types are supported for each register class.

+

Adding support for new architectures

+

Adding inline assembly support to an architecture is mostly a matter of defining the registers and +register classes for that architecture. All the definitions for register classes are located in +compiler/rustc_target/asm/.

+

Additionally you will need to implement lowering of these register classes to LLVM constraint codes +in compiler/rustc_codegen_llvm/asm.rs.

+

When adding a new architecture, make sure to cross-reference with the LLVM source code:

+
    +
  • LLVM has restrictions on which types can be used with a particular constraint code. Refer to the +getRegForInlineAsmConstraint function in lib/Target/${ARCH}/${ARCH}ISelLowering.cpp.
  • +
  • LLVM reserves certain registers for its internal use, which causes them to not be saved/restored +properly around inline assembly blocks. These registers are listed in the getReservedRegs +function in lib/Target/${ARCH}/${ARCH}RegisterInfo.cpp. Any "conditionally" reserved register +such as the frame/base pointer must always be treated as reserved for Rust purposes because we +can't know ahead of time whether a function will require a frame/base pointer.
  • +
+

Tests

+

Various tests for inline assembly are available:

+
    +
  • tests/assembly/asm
  • +
  • tests/ui/asm
  • +
  • tests/codegen/asm-*
  • +
+

Every architecture supported by inline assembly must have exhaustive tests in +tests/assembly/asm which test all combinations of register classes and types.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/ast-lowering.html b/ast-lowering.html new file mode 100644 index 000000000..f091aa826 --- /dev/null +++ b/ast-lowering.html @@ -0,0 +1,264 @@ + + + + + + Lowering AST to HIR - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

AST lowering

+

The AST lowering step converts AST to HIR. +This means many structures are removed if they are irrelevant +for type analysis or similar syntax agnostic analyses. Examples +of such structures include but are not limited to

+
    +
  • Parenthesis +
      +
    • Removed without replacement, the tree structure makes order explicit
    • +
    +
  • +
  • for loops and while (let) loops +
      +
    • Converted to loop + match and some let bindings
    • +
    +
  • +
  • if let +
      +
    • Converted to match
    • +
    +
  • +
  • Universal impl Trait +
      +
    • Converted to generic arguments +(but with some flags, to know that the user didn't write them)
    • +
    +
  • +
  • Existential impl Trait +
      +
    • Converted to a virtual existential type declaration
    • +
    +
  • +
+

Lowering needs to uphold several invariants in order to not trigger the +sanity checks in compiler/rustc_passes/src/hir_id_validator.rs:

+
    +
  1. A HirId must be used if created. So if you use the lower_node_id, +you must use the resulting NodeId or HirId (either is fine, since +any NodeIds in the HIR are checked for existing HirIds)
  2. +
  3. Lowering a HirId must be done in the scope of the owning item. +This means you need to use with_hir_id_owner if you are creating parts +of an item other than the one being currently lowered. This happens for +example during the lowering of existential impl Trait
  4. +
  5. A NodeId that will be placed into a HIR structure must be lowered, +even if its HirId is unused. Calling +let _ = self.lower_node_id(node_id); is perfectly legitimate.
  6. +
  7. If you are creating new nodes that didn't exist in the AST, you must +create new ids for them. This is done by calling the next_id method, +which produces both a new NodeId as well as automatically lowering it +for you so you also get the HirId.
  8. +
+

If you are creating new DefIds, since each DefId needs to have a +corresponding NodeId, it is advisable to add these NodeIds to the +AST so you don't have to generate new ones during lowering. This has +the advantage of creating a way to find the DefId of something via its +NodeId. If lowering needs this DefId in multiple places, you can't +generate a new NodeId in all those places because you'd also get a new +DefId then. With a NodeId from the AST this is not an issue.

+

Having the NodeId also allows the DefCollector to generate the DefIds +instead of lowering having to do it on the fly. Centralizing the DefId +generation in one place makes it easier to refactor and reason about.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/ast-validation.html b/ast-validation.html new file mode 100644 index 000000000..1341226b3 --- /dev/null +++ b/ast-validation.html @@ -0,0 +1,229 @@ + + + + + + AST Validation - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

AST Validation

+

AST validation is a separate AST pass that visits each +item in the tree and performs simple checks. This pass +doesn't perform any complex analysis, type checking or +name resolution.

+

Before performing any validation, the compiler first expands +the macros. Then this pass performs validations to check +that each AST item is in the correct state. And when this pass +is done, the compiler runs the crate resolution pass.

+

Validations

+

Validations are defined in AstValidator type, which +itself is located in rustc_ast_passes crate. This +type implements various simple checks which emit errors +when certain language rules are broken.

+

In addition, AstValidator implements Visitor trait +that defines how to visit AST items (which can be functions, +traits, enums, etc).

+

For each item, visitor performs specific checks. For +example, when visiting a function declaration, +AstValidator checks that the function has:

+
    +
  • no more than u16::MAX parameters;
  • +
  • c-variadic argument goes the last in the declaration;
  • +
  • documentation comments aren't applied to function parameters;
  • +
  • and other validations.
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/attributes.html b/attributes.html new file mode 100644 index 000000000..30009f533 --- /dev/null +++ b/attributes.html @@ -0,0 +1,243 @@ + + + + + + Attributes - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Attributes

+

Attributes come in two types: inert (or built-in) and active (non-builtin).

+

Builtin/inert attributes

+

These attributes are defined in the compiler itself, in +compiler/rustc_feature/src/builtin_attrs.rs.

+

Examples include #[allow] and #[macro_use].

+

These attributes have several important characteristics:

+
    +
  • They are always in scope, and do not participate in typical path-based resolution.
  • +
  • They cannot be renamed. For example, use allow as foo will compile, but writing #[foo] will +produce an error.
  • +
  • They are 'inert', meaning they are left as-is by the macro expansion code. +As a result, any behavior comes as a result of the compiler explicitly checking for their presence. +For example, lint-related code explicitly checks for #[allow], #[warn], #[deny], and +#[forbid], rather than the behavior coming from the expansion of the attributes themselves.
  • +
+

'Non-builtin'/'active' attributes

+

These attributes are defined by a crate - either the standard library, or a proc-macro crate.

+

Important: Many non-builtin attributes, such as #[derive], are still considered part of the +core Rust language. However, they are not called 'builtin attributes', since they have a +corresponding definition in the standard library.

+

Definitions of non-builtin attributes take two forms:

+
    +
  1. Proc-macro attributes, defined via a function annotated with #[proc_macro_attribute] in a +proc-macro crate.
  2. +
  3. AST-based attributes, defined in the standard library. These attributes have special 'stub' +macros defined in places like library/core/src/macros/mod.rs.
  4. +
+

These definitions exist to allow the macros to participate in typical path-based resolution - they +can be imported, re-exported, and renamed just like any other item definition. However, the body of +the definition is empty. Instead, the macro is annotated with the #[rustc_builtin_macro] +attribute, which tells the compiler to run a corresponding function in rustc_builtin_macros.

+

All non-builtin attributes have the following characteristics:

+
    +
  • Like all other definitions (e.g. structs), they must be brought into scope via an import. +Many standard library attributes are included in the prelude - this is why writing #[derive] +works without an import.
  • +
  • They participate in macro expansion. The implementation of the macro may leave the attribute +target unchanged, modify the target, produce new AST nodes, or remove the target entirely.
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/ayu-highlight.css b/ayu-highlight.css new file mode 100644 index 000000000..32c943222 --- /dev/null +++ b/ayu-highlight.css @@ -0,0 +1,78 @@ +/* +Based off of the Ayu theme +Original by Dempfi (https://github.com/dempfi/ayu) +*/ + +.hljs { + display: block; + overflow-x: auto; + background: #191f26; + color: #e6e1cf; +} + +.hljs-comment, +.hljs-quote { + color: #5c6773; + font-style: italic; +} + +.hljs-variable, +.hljs-template-variable, +.hljs-attribute, +.hljs-attr, +.hljs-regexp, +.hljs-link, +.hljs-selector-id, +.hljs-selector-class { + color: #ff7733; +} + +.hljs-number, +.hljs-meta, +.hljs-builtin-name, +.hljs-literal, +.hljs-type, +.hljs-params { + color: #ffee99; +} + +.hljs-string, +.hljs-bullet { + color: #b8cc52; +} + +.hljs-title, +.hljs-built_in, +.hljs-section { + color: #ffb454; +} + +.hljs-keyword, +.hljs-selector-tag, +.hljs-symbol { + color: #ff7733; +} + +.hljs-name { + color: #36a3d9; +} + +.hljs-tag { + color: #00568d; +} + +.hljs-emphasis { + font-style: italic; +} + +.hljs-strong { + font-weight: bold; +} + +.hljs-addition { + color: #91b362; +} + +.hljs-deletion { + color: #d96c75; +} diff --git a/backend/backend-agnostic.html b/backend/backend-agnostic.html new file mode 100644 index 000000000..78919d2b7 --- /dev/null +++ b/backend/backend-agnostic.html @@ -0,0 +1,387 @@ + + + + + + Backend Agnostic Codegen - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Backend Agnostic Codegen

+ +

rustc_codegen_ssa +provides an abstract interface for all backends to implement, +namely LLVM, Cranelift, and GCC.

+

Below is some background information on the refactoring that created this +abstract interface.

+

Refactoring of rustc_codegen_llvm

+

by Denis Merigoux, October 23rd 2018

+

State of the code before the refactoring

+

All the code related to the compilation of MIR into LLVM IR was contained +inside the rustc_codegen_llvm crate. Here is the breakdown of the most +important elements:

+
    +
  • the back folder (7,800 LOC) implements the mechanisms for creating the +different object files and archive through LLVM, but also the communication +mechanisms for parallel code generation;
  • +
  • the debuginfo (3,200 LOC) folder contains all code that passes debug +information down to LLVM;
  • +
  • the llvm (2,200 LOC) folder defines the FFI necessary to communicate with +LLVM using the C++ API;
  • +
  • the mir (4,300 LOC) folder implements the actual lowering from MIR to LLVM +IR;
  • +
  • the base.rs (1,300 LOC) file contains some helper functions but also the +high-level code that launches the code generation and distributes the work.
  • +
  • the builder.rs (1,200 LOC) file contains all the functions generating +individual LLVM IR instructions inside a basic block;
  • +
  • the common.rs (450 LOC) contains various helper functions and all the +functions generating LLVM static values;
  • +
  • the type_.rs (300 LOC) defines most of the type translations to LLVM IR.
  • +
+

The goal of this refactoring is to separate inside this crate code that is +specific to the LLVM from code that can be reused for other rustc backends. For +instance, the mir folder is almost entirely backend-specific but it relies +heavily on other parts of the crate. The separation of the code must not affect +the logic of the code nor its performance.

+

For these reasons, the separation process involves two transformations that +have to be done at the same time for the resulting code to compile :

+
    +
  1. replace all the LLVM-specific types by generics inside function signatures +and structure definitions;
  2. +
  3. encapsulate all functions calling the LLVM FFI inside a set of traits that +will define the interface between backend-agnostic code and the backend.
  4. +
+

While the LLVM-specific code will be left in rustc_codegen_llvm, all the new +traits and backend-agnostic code will be moved in rustc_codegen_ssa (name +suggestion by @eddyb).

+

Generic types and structures

+

@irinagpopa started to parametrize the types of rustc_codegen_llvm by a +generic Value type, implemented in LLVM by a reference &'ll Value. This +work has been extended to all structures inside the mir folder and elsewhere, +as well as for LLVM's BasicBlock and Type types.

+

The two most important structures for the LLVM codegen are CodegenCx and +Builder. They are parametrized by multiple lifetime parameters and the type +for Value.

+
struct CodegenCx<'ll, 'tcx> {
+  /* ... */
+}
+
+struct Builder<'a, 'll, 'tcx> {
+  cx: &'a CodegenCx<'ll, 'tcx>,
+  /* ... */
+}
+
+

CodegenCx is used to compile one codegen-unit that can contain multiple +functions, whereas Builder is created to compile one basic block.

+

The code in rustc_codegen_llvm has to deal with multiple explicit lifetime +parameters, that correspond to the following:

+
    +
  • 'tcx is the longest lifetime, that corresponds to the original TyCtxt +containing the program's information;
  • +
  • 'a is a short-lived reference of a CodegenCx or another object inside a +struct;
  • +
  • 'll is the lifetime of references to LLVM objects such as Value or +Type.
  • +
+

Although there are already many lifetime parameters in the code, making it +generic uncovered situations where the borrow-checker was passing only due to +the special nature of the LLVM objects manipulated (they are extern pointers). +For instance, an additional lifetime parameter had to be added to +LocalAnalyser in analyse.rs, leading to the definition:

+
struct LocalAnalyzer<'mir, 'a, 'tcx> {
+  /* ... */
+}
+
+

However, the two most important structures CodegenCx and Builder are not +defined in the backend-agnostic code. Indeed, their content is highly specific +of the backend and it makes more sense to leave their definition to the backend +implementor than to allow just a narrow spot via a generic field for the +backend's context.

+

Traits and interface

+

Because they have to be defined by the backend, CodegenCx and Builder will +be the structures implementing all the traits defining the backend's interface. +These traits are defined in the folder rustc_codegen_ssa/traits and all the +backend-agnostic code is parametrized by them. For instance, let us explain how +a function in base.rs is parametrized:

+
pub fn codegen_instance<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
+    cx: &'a Bx::CodegenCx,
+    instance: Instance<'tcx>
+) {
+    /* ... */
+}
+
+

In this signature, we have the two lifetime parameters explained earlier and +the master type Bx which satisfies the trait BuilderMethods corresponding +to the interface satisfied by the Builder struct. The BuilderMethods +defines an associated type Bx::CodegenCx that itself satisfies the +CodegenMethods traits implemented by the struct CodegenCx.

+

On the trait side, here is an example with part of the definition of +BuilderMethods in traits/builder.rs:

+
pub trait BuilderMethods<'a, 'tcx>:
+    HasCodegen<'tcx>
+    + DebugInfoBuilderMethods<'tcx>
+    + ArgTypeMethods<'tcx>
+    + AbiBuilderMethods<'tcx>
+    + IntrinsicCallMethods<'tcx>
+    + AsmBuilderMethods<'tcx>
+{
+    fn new_block<'b>(
+        cx: &'a Self::CodegenCx,
+        llfn: Self::Function,
+        name: &'b str
+    ) -> Self;
+    /* ... */
+    fn cond_br(
+        &mut self,
+        cond: Self::Value,
+        then_llbb: Self::BasicBlock,
+        else_llbb: Self::BasicBlock,
+    );
+    /* ... */
+}
+
+

Finally, a master structure implementing the ExtraBackendMethods trait is +used for high-level codegen-driving functions like codegen_crate in +base.rs. For LLVM, it is the empty LlvmCodegenBackend. +ExtraBackendMethods should be implemented by the same structure that +implements the CodegenBackend defined in +rustc_codegen_utils/codegen_backend.rs.

+

During the traitification process, certain functions have been converted from +methods of a local structure to methods of CodegenCx or Builder and a +corresponding self parameter has been added. Indeed, LLVM stores information +internally that it can access when called through its API. This information +does not show up in a Rust data structure carried around when these methods are +called. However, when implementing a Rust backend for rustc, these methods +will need information from CodegenCx, hence the additional parameter (unused +in the LLVM implementation of the trait).

+

State of the code after the refactoring

+

The traits offer an API which is very similar to the API of LLVM. This is not +the best solution since LLVM has a very special way of doing things: when +adding another backend, the traits definition might be changed in order to +offer more flexibility.

+

However, the current separation between backend-agnostic and LLVM-specific code +has allowed the reuse of a significant part of the old rustc_codegen_llvm. +Here is the new LOC breakdown between backend-agnostic (BA) and LLVM for the +most important elements:

+
    +
  • back folder: 3,800 (BA) vs 4,100 (LLVM);
  • +
  • mir folder: 4,400 (BA) vs 0 (LLVM);
  • +
  • base.rs: 1,100 (BA) vs 250 (LLVM);
  • +
  • builder.rs: 1,400 (BA) vs 0 (LLVM);
  • +
  • common.rs: 350 (BA) vs 350 (LLVM);
  • +
+

The debuginfo folder has been left almost untouched by the splitting and is +specific to LLVM. Only its high-level features have been traitified.

+

The new traits folder has 1500 LOC only for trait definitions. Overall, the +27,000 LOC-sized old rustc_codegen_llvm code has been split into the new +18,500 LOC-sized new rustc_codegen_llvm and the 12,000 LOC-sized +rustc_codegen_ssa. We can say that this refactoring allowed the reuse of +approximately 10,000 LOC that would otherwise have had to be duplicated between +the multiple backends of rustc.

+

The refactored version of rustc's backend introduced no regression over the +test suite nor in performance benchmark, which is in coherence with the nature +of the refactoring that used only compile-time parametricity (no trait +objects).

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/codegen.html b/backend/codegen.html new file mode 100644 index 000000000..f8d509f8c --- /dev/null +++ b/backend/codegen.html @@ -0,0 +1,262 @@ + + + + + + Code Generation - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Code generation

+

Code generation (or "codegen") is the part of the compiler +that actually generates an executable binary. +Usually, rustc uses LLVM for code generation, +but there is also support for Cranelift and GCC. +The key is that rustc doesn't implement codegen itself. +It's worth noting, though, that in the Rust source code, +many parts of the backend have codegen in their names +(there are no hard boundaries).

+
+

NOTE: If you are looking for hints on how to debug code generation bugs, +please see this section of the debugging chapter.

+
+

What is LLVM?

+

LLVM is "a collection of modular and reusable compiler and +toolchain technologies". In particular, the LLVM project contains a pluggable +compiler backend (also called "LLVM"), which is used by many compiler projects, +including the clang C compiler and our beloved rustc.

+

LLVM takes input in the form of LLVM IR. It is basically assembly code with +additional low-level types and annotations added. These annotations are helpful +for doing optimizations on the LLVM IR and outputted machine code. The end +result of all this is (at long last) something executable (e.g. an ELF object, +an EXE, or wasm).

+

There are a few benefits to using LLVM:

+
    +
  • We don't have to write a whole compiler backend. This reduces implementation +and maintenance burden.
  • +
  • We benefit from the large suite of advanced optimizations that the LLVM +project has been collecting.
  • +
  • We can automatically compile Rust to any of the platforms for which LLVM has +support. For example, as soon as LLVM added support for wasm, voila! rustc, +clang, and a bunch of other languages were able to compile to wasm! (Well, +there was some extra stuff to be done, but we were 90% there anyway).
  • +
  • We and other compiler projects benefit from each other. For example, when the +Spectre and Meltdown security vulnerabilities were discovered, +only LLVM needed to be patched.
  • +
+

Running LLVM, linking, and metadata generation

+

Once LLVM IR for all of the functions and statics, etc is built, it is time to +start running LLVM and its optimization passes. LLVM IR is grouped into +"modules". Multiple "modules" can be codegened at the same time to aid in +multi-core utilization. These "modules" are what we refer to as codegen +units. These units were established way back during monomorphization +collection phase.

+

Once LLVM produces objects from these modules, these objects are passed to the +linker along with, optionally, the metadata object and an archive or an +executable is produced.

+

It is not necessarily the codegen phase described above that runs the +optimizations. With certain kinds of LTO, the optimization might happen at the +linking time instead. It is also possible for some optimizations to happen +before objects are passed on to the linker and some to happen during the +linking.

+

This all happens towards the very end of compilation. The code for this can be +found in rustc_codegen_ssa::back and +rustc_codegen_llvm::back. Sadly, this piece of code is not +really well-separated into LLVM-dependent code; the rustc_codegen_ssa +contains a fair amount of code specific to the LLVM backend.

+

Once these components are done with their work you end up with a number of +files in your filesystem corresponding to the outputs you have requested.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/debugging.html b/backend/debugging.html new file mode 100644 index 000000000..525eb87d2 --- /dev/null +++ b/backend/debugging.html @@ -0,0 +1,437 @@ + + + + + + Debugging LLVM - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Debugging LLVM

+
+

NOTE: If you are looking for info about code generation, please see this +chapter instead.

+
+

This section is about debugging compiler bugs in code generation (e.g. why the +compiler generated some piece of code or crashed in LLVM). LLVM is a big +project on its own that probably needs to have its own debugging document (not +that I could find one). But here are some tips that are important in a rustc +context:

+

Minimize the example

+

As a general rule, compilers generate lots of information from analyzing code. +Thus, a useful first step is usually to find a minimal example. One way to do +this is to

+
    +
  1. +

    create a new crate that reproduces the issue (e.g. adding whatever crate is +at fault as a dependency, and using it from there)

    +
  2. +
  3. +

    minimize the crate by removing external dependencies; that is, moving +everything relevant to the new crate

    +
  4. +
  5. +

    further minimize the issue by making the code shorter (there are tools that +help with this like creduce)

    +
  6. +
+

For more discussion on methodology for steps 2 and 3 above, there is an +epic blog post from pnkfelix specifically about Rust program minimization.

+

Enable LLVM internal checks

+

The official compilers (including nightlies) have LLVM assertions disabled, +which means that LLVM assertion failures can show up as compiler crashes (not +ICEs but "real" crashes) and other sorts of weird behavior. If you are +encountering these, it is a good idea to try using a compiler with LLVM +assertions enabled - either an "alt" nightly or a compiler you build yourself +by setting [llvm] assertions=true in your config.toml - and see whether +anything turns up.

+

The rustc build process builds the LLVM tools into +./build/<host-triple>/llvm/bin. They can be called directly. +These tools include:

+
    +
  • llc, which compiles bitcode (.bc files) to executable code; this can be used to +replicate LLVM backend bugs.
  • +
  • opt, a bitcode transformer that runs LLVM optimization passes.
  • +
  • bugpoint, which reduces large test cases to small, useful ones.
  • +
  • and many others, some of which are referenced in the text below.
  • +
+

By default, the Rust build system does not check for changes to the LLVM source code or +its build configuration settings. So, if you need to rebuild the LLVM that is linked +into rustc, first delete the file llvm-finished-building, which should be located +in build/<host-triple>/llvm/.

+

The default rustc compilation pipeline has multiple codegen units, which is +hard to replicate manually and means that LLVM is called multiple times in +parallel. If you can get away with it (i.e. if it doesn't make your bug +disappear), passing -C codegen-units=1 to rustc will make debugging easier.

+

Get your hands on raw LLVM input

+

For rustc to generate LLVM IR, you need to pass the --emit=llvm-ir flag. If +you are building via cargo, use the RUSTFLAGS environment variable (e.g. +RUSTFLAGS='--emit=llvm-ir'). This causes rustc to spit out LLVM IR into the +target directory.

+

cargo llvm-ir [options] path spits out the LLVM IR for a particular function +at path. (cargo install cargo-asm installs cargo asm and cargo llvm-ir). --build-type=debug emits code for debug builds. There are also +other useful options. Also, debug info in LLVM IR can clutter the output a lot: +RUSTFLAGS="-C debuginfo=0" is really useful.

+

RUSTFLAGS="-C save-temps" outputs LLVM bitcode (not the same as IR) at +different stages during compilation, which is sometimes useful. The output LLVM +bitcode will be in .bc files in the compiler's output directory, set via the +--out-dir DIR argument to rustc.

+
    +
  • +

    If you are hitting an assertion failure or segmentation fault from the LLVM +backend when invoking rustc itself, it is a good idea to try passing each +of these .bc files to the llc command, and see if you get the same +failure. (LLVM developers often prefer a bug reduced to a .bc file over one +that uses a Rust crate for its minimized reproduction.)

    +
  • +
  • +

    To get human readable versions of the LLVM bitcode, one just needs to convert +the bitcode (.bc) files to .ll files using llvm-dis, which should be in +the target local compilation of rustc.

    +
  • +
+

Note that rustc emits different IR depending on whether -O is enabled, even +without LLVM's optimizations, so if you want to play with the IR rustc emits, +you should:

+
$ rustc +local my-file.rs --emit=llvm-ir -O -C no-prepopulate-passes \
+    -C codegen-units=1
+$ OPT=./build/$TRIPLE/llvm/bin/opt
+$ $OPT -S -O2 < my-file.ll > my
+
+

If you just want to get the LLVM IR during the LLVM pipeline, to e.g. see which +IR causes an optimization-time assertion to fail, or to see when LLVM performs +a particular optimization, you can pass the rustc flag -C llvm-args=-print-after-all, and possibly add -C llvm-args='-filter-print-funcs=EXACT_FUNCTION_NAME (e.g. -C llvm-args='-filter-print-funcs=_ZN11collections3str21_$LT$impl$u20$str$GT$\ 7replace17hbe10ea2e7c809b0bE').

+

That produces a lot of output into standard error, so you'll want to pipe that +to some file. Also, if you are using neither -filter-print-funcs nor -C codegen-units=1, then, because the multiple codegen units run in parallel, the +printouts will mix together and you won't be able to read anything.

+
    +
  • +

    One caveat to the aforementioned methodology: the -print family of options +to LLVM only prints the IR unit that the pass runs on (e.g., just a +function), and does not include any referenced declarations, globals, +metadata, etc. This means you cannot in general feed the output of -print +into llc to reproduce a given problem.

    +
  • +
  • +

    Within LLVM itself, calling F.getParent()->dump() at the beginning of +SafeStackLegacyPass::runOnFunction will dump the whole module, which +may provide better basis for reproduction. (However, you +should be able to get that same dump from the .bc files dumped by +-C save-temps.)

    +
  • +
+

If you want just the IR for a specific function (say, you want to see why it +causes an assertion or doesn't optimize correctly), you can use llvm-extract, +e.g.

+
$ ./build/$TRIPLE/llvm/bin/llvm-extract \
+    -func='_ZN11collections3str21_$LT$impl$u20$str$GT$7replace17hbe10ea2e7c809b0bE' \
+    -S \
+    < unextracted.ll \
+    > extracted.ll
+
+

Investigate LLVM optimization passes

+

If you are seeing incorrect behavior due to an optimization pass, a very handy +LLVM option is -opt-bisect-limit, which takes an integer denoting the index +value of the highest pass to run. Index values for taken passes are stable +from run to run; by coupling this with software that automates bisecting the +search space based on the resulting program, an errant pass can be quickly +determined. When an -opt-bisect-limit is specified, all runs are displayed +to standard error, along with their index and output indicating if the +pass was run or skipped. Setting the limit to an index of -1 (e.g., +RUSTFLAGS="-C llvm-args=-opt-bisect-limit=-1") will show all passes and +their corresponding index values.

+

If you want to play with the optimization pipeline, you can use the opt tool +from ./build/<host-triple>/llvm/bin/ with the LLVM IR emitted by rustc.

+

When investigating the implementation of LLVM itself, you should be +aware of its internal debug infrastructure. +This is provided in LLVM Debug builds, which you enable for rustc +LLVM builds by changing this setting in the config.toml:

+
[llvm]
+# Indicates whether the LLVM assertions are enabled or not
+assertions = true
+
+# Indicates whether the LLVM build is a Release or Debug build
+optimize = false
+
+

The quick summary is:

+
    +
  • Setting assertions=true enables coarse-grain debug messaging. +
      +
    • beyond that, setting optimize=false enables fine-grain debug messaging.
    • +
    +
  • +
  • LLVM_DEBUG(dbgs() << msg) in LLVM is like debug!(msg) in rustc.
  • +
  • The -debug option turns on all messaging; it is like setting the +environment variable RUSTC_LOG=debug in rustc.
  • +
  • The -debug-only=<pass1>,<pass2> variant is more selective; it is like +setting the environment variable RUSTC_LOG=path1,path2 in rustc.
  • +
+

Getting help and asking questions

+

If you have some questions, head over to the rust-lang Zulip and +specifically the #t-compiler/wg-llvm stream.

+

Compiler options to know and love

+

The -C help and -Z help compiler switches will list out a variety +of interesting options you may find useful. Here are a few of the most +common that pertain to LLVM development (some of them are employed in the +tutorial above):

+
    +
  • The --emit llvm-ir option emits a <filename>.ll file with LLVM IR in textual format +
      +
    • The --emit llvm-bc option emits in bytecode format (<filename>.bc)
    • +
    +
  • +
  • Passing -C llvm-args=<foo> allows passing pretty much all the +options that tools like llc and opt would accept; +e.g. -C llvm-args=-print-before-all to print IR before every LLVM +pass.
  • +
  • The -C no-prepopulate-passes will avoid pre-populate the LLVM pass +manager with a list of passes. This will allow you to view the LLVM +IR that rustc generates, not the LLVM IR after optimizations.
  • +
  • The -C passes=val option allows you to supply a space separated list of extra LLVM passes to run
  • +
  • The -C save-temps option saves all temporary output files during compilation
  • +
  • The -Z print-llvm-passes option will print out LLVM optimization passes being run
  • +
  • The -Z time-llvm-passes option measures the time of each LLVM pass
  • +
  • The -Z verify-llvm-ir option will verify the LLVM IR for correctness
  • +
  • The -Z no-parallel-backend will disable parallel compilation of distinct compilation units
  • +
  • The -Z llvm-time-trace option will output a Chrome profiler compatible JSON file +which contains details and timings for LLVM passes.
  • +
  • The -C llvm-args=-opt-bisect-limit=<index> option allows for bisecting LLVM +optimizations.
  • +
+

Filing LLVM bug reports

+

When filing an LLVM bug report, you will probably want some sort of minimal +working example that demonstrates the problem. The Godbolt compiler explorer is +really helpful for this.

+
    +
  1. +

    Once you have some LLVM IR for the problematic code (see above), you can +create a minimal working example with Godbolt. Go to +llvm.godbolt.org.

    +
  2. +
  3. +

    Choose LLVM-IR as programming language.

    +
  4. +
  5. +

    Use llc to compile the IR to a particular target as is:

    +
      +
    • There are some useful flags: -mattr enables target features, -march= +selects the target, -mcpu= selects the CPU, etc.
    • +
    • Commands like llc -march=help output all architectures available, which +is useful because sometimes the Rust arch names and the LLVM names do not +match.
    • +
    • If you have compiled rustc yourself somewhere, in the target directory +you have binaries for llc, opt, etc.
    • +
    +
  6. +
  7. +

    If you want to optimize the LLVM-IR, you can use opt to see how the LLVM +optimizations transform it.

    +
  8. +
  9. +

    Once you have a godbolt link demonstrating the issue, it is pretty easy to +fill in an LLVM bug. Just visit their github issues page.

    +
  10. +
+

Porting bug fixes from LLVM

+

Once you've identified the bug as an LLVM bug, you will sometimes +find that it has already been reported and fixed in LLVM, but we haven't +gotten the fix yet (or perhaps you are familiar enough with LLVM to fix it yourself).

+

In that case, we can sometimes opt to port the fix for the bug +directly to our own LLVM fork, so that rustc can use it more easily. +Our fork of LLVM is maintained in rust-lang/llvm-project. Once +you've landed the fix there, you'll also need to land a PR modifying +our submodule commits -- ask around on Zulip for help.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/implicit-caller-location.html b/backend/implicit-caller-location.html new file mode 100644 index 000000000..b4fb641d9 --- /dev/null +++ b/backend/implicit-caller-location.html @@ -0,0 +1,431 @@ + + + + + + Implicit Caller Location - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Implicit Caller Location

+ +

Approved in RFC 2091, this feature enables the accurate reporting of caller location during panics +initiated from functions like Option::unwrap, Result::expect, and Index::index. This feature +adds the #[track_caller] attribute for functions, the +caller_location intrinsic, and the stabilization-friendly +core::panic::Location::caller wrapper.

+

Motivating Example

+

Take this example program:

+
fn main() {
+    let foo: Option<()> = None;
+    foo.unwrap(); // this should produce a useful panic message!
+}
+
+

Prior to Rust 1.42, panics like this unwrap() printed a location in core:

+
$ rustc +1.41.0 example.rs; example.exe
+thread 'main' panicked at 'called `Option::unwrap()` on a `None` value',...core\macros\mod.rs:15:40
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
+
+

As of 1.42, we get a much more helpful message:

+
$ rustc +1.42.0 example.rs; example.exe
+thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', example.rs:3:5
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+
+

These error messages are achieved through a combination of changes to panic! internals to make use +of core::panic::Location::caller and a number of #[track_caller] annotations in the standard +library which propagate caller information.

+

Reading Caller Location

+

Previously, panic! made use of the file!(), line!(), and column!() macros to construct a +Location pointing to where the panic occurred. These macros couldn't be given an overridden +location, so functions which intentionally invoked panic! couldn't provide their own location, +hiding the actual source of error.

+

Internally, panic!() now calls core::panic::Location::caller() to find out where it +was expanded. This function is itself annotated with #[track_caller] and wraps the +caller_location compiler intrinsic implemented by rustc. This intrinsic is easiest +explained in terms of how it works in a const context.

+

Caller Location in const

+

There are two main phases to returning the caller location in a const context: walking up the stack +to find the right location and allocating a const value to return.

+

Finding the right Location

+

In a const context we "walk up the stack" from where the intrinsic is invoked, stopping when we +reach the first function call in the stack which does not have the attribute. This walk is in +InterpCx::find_closest_untracked_caller_location().

+

Starting at the bottom, we iterate up over stack Frames in the +InterpCx::stack, calling +InstanceKind::requires_caller_location on the +Instances from each Frame. We stop once we find one that returns false and +return the span of the previous frame which was the "topmost" tracked function.

+

Allocating a static Location

+

Once we have a Span, we need to allocate static memory for the Location, which is performed by +the TyCtxt::const_caller_location() query. Internally this calls +InterpCx::alloc_caller_location() and results in a unique +memory kind (MemoryKind::CallerLocation). The SSA codegen backend is able +to emit code for these same values, and we use this code there as well.

+

Once our Location has been allocated in static memory, our intrinsic returns a reference to it.

+

Generating code for #[track_caller] callees

+

To generate efficient code for a tracked function and its callers, we need to provide the same +behavior from the intrinsic's point of view without having a stack to walk up at runtime. We invert +the approach: as we grow the stack down we pass an additional argument to calls of tracked functions +rather than walking up the stack when the intrinsic is called. That additional argument can be +returned wherever the caller location is queried.

+

The argument we append is of type &'static core::panic::Location<'static>. A reference was chosen +to avoid unnecessary copying because a pointer is a third the size of +std::mem::size_of::<core::panic::Location>() == 24 at time of writing.

+

When generating a call to a function which is tracked, we pass the location argument the value of +FunctionCx::get_caller_location.

+

If the calling function is tracked, get_caller_location returns the local in +FunctionCx::caller_location which was populated by the current caller's caller. +In these cases the intrinsic "returns" a reference which was actually provided in an argument to its +caller.

+

If the calling function is not tracked, get_caller_location allocates a Location static from +the current Span and returns a reference to that.

+

We more efficiently achieve the same behavior as a loop starting from the bottom by passing a single +&Location value through the caller_location fields of multiple FunctionCxs as we grow the +stack downward.

+

Codegen examples

+

What does this transformation look like in practice? Take this example which uses the new feature:

+
#![feature(track_caller)]
+use std::panic::Location;
+
+#[track_caller]
+fn print_caller() {
+    println!("called from {}", Location::caller());
+}
+
+fn main() {
+    print_caller();
+}
+
+

Here print_caller() appears to take no arguments, but we compile it to something like this:

+
#![feature(panic_internals)]
+use std::panic::Location;
+
+fn print_caller(caller: &Location) {
+    println!("called from {}", caller);
+}
+
+fn main() {
+    print_caller(&Location::internal_constructor(file!(), line!(), column!()));
+}
+
+

Dynamic Dispatch

+

In codegen contexts we have to modify the callee ABI to pass this information down the stack, but +the attribute expressly does not modify the type of the function. The ABI change must be +transparent to type checking and remain sound in all uses.

+

Direct calls to tracked functions will always know the full codegen flags for the callee and can +generate appropriate code. Indirect callers won't have this information and it's not encoded in +the type of the function pointer they call, so we generate a ReifyShim around the function +whenever taking a pointer to it. This shim isn't able to report the actual location of the indirect +call (the function's definition site is reported instead), but it prevents miscompilation and is +probably the best we can do without modifying fully-stabilized type signatures.

+
+

Note: We always emit a ReifyShim when taking a pointer to a tracked function. While the +constraint here is imposed by codegen contexts, we don't know during MIR construction of the shim +whether we'll be called in a const context (safe to ignore shim) or in a codegen context (unsafe +to ignore shim). Even if we did know, the results from const and codegen contexts must agree.

+
+

The Attribute

+

The #[track_caller] attribute is checked alongside other codegen attributes to ensure the +function:

+
    +
  • has the "Rust" ABI (as opposed to e.g., "C")
  • +
  • is not a closure
  • +
  • is not #[naked]
  • +
+

If the use is valid, we set CodegenFnAttrsFlags::TRACK_CALLER. This flag influences +the return value of InstanceKind::requires_caller_location which is in turn +used in both const and codegen contexts to ensure correct propagation.

+

Traits

+

When applied to trait method implementations, the attribute works as it does for regular functions.

+

When applied to a trait method prototype, the attribute applies to all implementations of the +method. When applied to a default trait method implementation, the attribute takes effect on +that implementation and any overrides.

+

Examples:

+
#![feature(track_caller)]
+
+macro_rules! assert_tracked {
+    () => {{
+        let location = std::panic::Location::caller();
+        assert_eq!(location.file(), file!());
+        assert_ne!(location.line(), line!(), "line should be outside this fn");
+        println!("called at {}", location);
+    }};
+}
+
+trait TrackedFourWays {
+    /// All implementations inherit `#[track_caller]`.
+    #[track_caller]
+    fn blanket_tracked();
+
+    /// Implementors can annotate themselves.
+    fn local_tracked();
+
+    /// This implementation is tracked (overrides are too).
+    #[track_caller]
+    fn default_tracked() {
+        assert_tracked!();
+    }
+
+    /// Overrides of this implementation are tracked (it is too).
+    #[track_caller]
+    fn default_tracked_to_override() {
+        assert_tracked!();
+    }
+}
+
+/// This impl uses the default impl for `default_tracked` and provides its own for
+/// `default_tracked_to_override`.
+impl TrackedFourWays for () {
+    fn blanket_tracked() {
+        assert_tracked!();
+    }
+
+    #[track_caller]
+    fn local_tracked() {
+        assert_tracked!();
+    }
+
+    fn default_tracked_to_override() {
+        assert_tracked!();
+    }
+}
+
+fn main() {
+    <() as TrackedFourWays>::blanket_tracked();
+    <() as TrackedFourWays>::default_tracked();
+    <() as TrackedFourWays>::default_tracked_to_override();
+    <() as TrackedFourWays>::local_tracked();
+}
+
+

Background/History

+

Broadly speaking, this feature's goal is to improve common Rust error messages without breaking +stability guarantees, requiring modifications to end-user source, relying on platform-specific +debug-info, or preventing user-defined types from having the same error-reporting benefits.

+

Improving the output of these panics has been a goal of proposals since at least mid-2016 (see +non-viable alternatives in the approved RFC for details). It took two more years until RFC 2091 +was approved, much of its rationale for this feature's design having been discovered through the +discussion around several earlier proposals.

+

The design in the original RFC limited itself to implementations that could be done inside the +compiler at the time without significant refactoring. However in the year and a half between the +approval of the RFC and the actual implementation work, a revised design was proposed and written +up on the tracking issue. During the course of implementing that, it was also discovered that an +implementation was possible without modifying the number of arguments in a function's MIR, which +would simplify later stages and unlock use in traits.

+

Because the RFC's implementation strategy could not readily support traits, the semantics were not +originally specified. They have since been implemented following the path which seemed most correct +to the author and reviewers.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/libs-and-metadata.html b/backend/libs-and-metadata.html new file mode 100644 index 000000000..801c979b2 --- /dev/null +++ b/backend/libs-and-metadata.html @@ -0,0 +1,332 @@ + + + + + + Libraries and Metadata - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Libraries and Metadata

+

When the compiler sees a reference to an external crate, it needs to load some +information about that crate. This chapter gives an overview of that process, +and the supported file formats for crate libraries.

+

Libraries

+

A crate dependency can be loaded from an rlib, dylib, or rmeta file. A +key point of these file formats is that they contain rustc-specific +metadata. This metadata allows the compiler to discover enough +information about the external crate to understand the items it contains, +which macros it exports, and much more.

+

rlib

+

An rlib is an archive file, which is similar to a tar file. This file +format is specific to rustc, and may change over time. This file contains:

+
    +
  • Object code, which is the result of code generation. This is used during +regular linking. There is a separate .o file for each codegen unit. The +codegen step can be skipped with the -C linker-plugin-lto CLI option, which means each .o +file will only contain LLVM bitcode.
  • +
  • LLVM bitcode, which is a binary representation of LLVM's intermediate +representation, which is embedded as a section in the .o files. This can +be used for Link Time Optimization (LTO). This can be removed with the +-C embed-bitcode=no CLI option to improve compile times +and reduce disk space if LTO is not needed.
  • +
  • rustc metadata, in a file named lib.rmeta.
  • +
  • A symbol table, which is generally a list of symbols with offsets to the +object file that contain that symbol. This is pretty standard for archive +files.
  • +
+

dylib

+

A dylib is a platform-specific shared library. It includes the rustc +metadata in a special link section called .rustc in a compressed format.

+

rmeta

+

An rmeta file is custom binary format that contains the metadata for the +crate. This file can be used for fast "checks" of a project by skipping all +code generation (as is done with cargo check), collecting enough information +for documentation (as is done with cargo doc), or for +pipelining. This file is created if the +--emit=metadata CLI option is used.

+

rmeta files do not support linking, since they do not contain compiled +object files.

+

Metadata

+

The metadata contains a wide swath of different elements. This guide will not +go into detail of every field it contains. You are encouraged to browse the +CrateRoot definition to get a sense of the different elements it contains. +Everything about metadata encoding and decoding is in the rustc_metadata +package.

+

Here are a few highlights of things it contains:

+
    +
  • The version of the rustc compiler. The compiler will refuse to load files +from any other version.
  • +
  • The Strict Version Hash (SVH). This helps ensure the +correct dependency is loaded.
  • +
  • The Stable Crate Id. This is a hash used +to identify crates.
  • +
  • Information about all the source files in the library. This can be used for +a variety of things, such as diagnostics pointing to sources in a +dependency.
  • +
  • Information about exported macros, traits, types, and items. Generally, +anything that's needed to be known when a path references something inside a +crate dependency.
  • +
  • Encoded MIR. This is optional, and only encoded if needed for code +generation. cargo check skips this for performance reasons.
  • +
+

Strict Version Hash

+

The Strict Version Hash (SVH, also known as the "crate hash") is a 64-bit +hash that is used to ensure that the correct crate dependencies are loaded. It +is possible for a directory to contain multiple copies of the same dependency +built with different settings, or built from different sources. The crate +loader will skip any crates that have the wrong SVH.

+

The SVH is also used for the incremental compilation session filename, +though that usage is mostly historic.

+

The hash includes a variety of elements:

+
    +
  • Hashes of the HIR nodes.
  • +
  • All of the upstream crate hashes.
  • +
  • All of the source filenames.
  • +
  • Hashes of certain command-line flags (like -C metadata via the Stable +Crate Id, and all CLI options marked with [TRACKED]).
  • +
+

See compute_hir_hash for where the hash is actually computed.

+

Stable Crate Id

+

The StableCrateId is a 64-bit hash used to identify different crates with +potentially the same name. It is a hash of the crate name and all the +-C metadata CLI options computed in StableCrateId::new. It is +used in a variety of places, such as symbol name mangling, crate loading, and +much more.

+

By default, all Rust symbols are mangled and incorporate the stable crate id. +This allows multiple versions of the same crate to be included together. Cargo +automatically generates -C metadata hashes based on a variety of factors, +like the package version, source, and the target kind (a lib and test can have +the same crate name, so they need to be disambiguated).

+

Crate loading

+

Crate loading can have quite a few subtle complexities. During name +resolution, when an external crate is referenced (via an extern crate or +path), the resolver uses the CrateLoader which is responsible for finding +the crate libraries and loading the metadata for them. After the dependency +is loaded, the CrateLoader will provide the information the resolver needs +to perform its job (such as expanding macros, resolving paths, etc.).

+

To load each external crate, the CrateLoader uses a CrateLocator to +actually find the correct files for one specific crate. There is some great +documentation in the locator module that goes into detail on how loading +works, and I strongly suggest reading it to get the full picture.

+

The location of a dependency can come from several different places. Direct +dependencies are usually passed with --extern flags, and the loader can look +at those directly. Direct dependencies often have references to their own +dependencies, which need to be loaded, too. These are usually found by +scanning the directories passed with the -L flag for any file whose metadata +contains a matching crate name and SVH. The loader +will also look at the sysroot to find dependencies.

+

As crates are loaded, they are kept in the CStore with the crate metadata +wrapped in the CrateMetadata struct. After resolution and expansion, the +CStore will make its way into the GlobalCtxt for the rest of +compilation.

+

Pipelining

+

One trick to improve compile times is to start building a crate as soon as the +metadata for its dependencies is available. For a library, there is no need to +wait for the code generation of dependencies to finish. Cargo implements this +technique by telling rustc to emit an rmeta file for each +dependency as well as an rlib. As early as it can, rustc will +save the rmeta file to disk before it continues to the code generation +phase. The compiler sends a JSON message to let the build tool know that it +can start building the next crate if possible.

+

The crate loading system is smart enough to know when it +sees an rmeta file to use that if the rlib is not there (or has only been +partially written).

+

This pipelining isn't possible for binaries, because the linking phase will +require the code generation of all its dependencies. In the future, it may be +possible to further improve this scenario by splitting linking into a separate +command (see #64191).

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/lowering-mir.html b/backend/lowering-mir.html new file mode 100644 index 000000000..98822a074 --- /dev/null +++ b/backend/lowering-mir.html @@ -0,0 +1,240 @@ + + + + + + Lowering MIR - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Lowering MIR to a Codegen IR

+

Now that we have a list of symbols to generate from the collector, we need to +generate some sort of codegen IR. In this chapter, we will assume LLVM IR, +since that's what rustc usually uses. The actual monomorphization is performed +as we go, while we do the translation.

+

Recall that the backend is started by +rustc_codegen_ssa::base::codegen_crate. Eventually, this reaches +rustc_codegen_ssa::mir::codegen_mir, which does the lowering from +MIR to LLVM IR.

+

The code is split into modules which handle particular MIR primitives:

+ +

Before a function is translated a number of simple and primitive analysis +passes will run to help us generate simpler and more efficient LLVM IR. An +example of such an analysis pass would be figuring out which variables are +SSA-like, so that we can translate them to SSA directly rather than relying on +LLVM's mem2reg for those variables. The analysis can be found in +rustc_codegen_ssa::mir::analyze.

+

Usually a single MIR basic block will map to a LLVM basic block, with very few +exceptions: intrinsic or function calls and less basic MIR statements like +assert can result in multiple basic blocks. This is a perfect lede into the +non-portable LLVM-specific part of the code generation. Intrinsic generation is +fairly easy to understand as it involves very few abstraction levels in between +and can be found in rustc_codegen_llvm::intrinsic.

+

Everything else will use the builder interface. This is the code that gets +called in the rustc_codegen_ssa::mir::* modules discussed above.

+
+

TODO: discuss how constants are generated

+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/monomorph.html b/backend/monomorph.html new file mode 100644 index 000000000..0c1357de7 --- /dev/null +++ b/backend/monomorph.html @@ -0,0 +1,317 @@ + + + + + + Monomorphization - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Monomorphization

+ +

As you probably know, Rust has a very expressive type system that has extensive +support for generic types. But of course, assembly is not generic, so we need +to figure out the concrete types of all the generics before the code can +execute.

+

Different languages handle this problem differently. For example, in some +languages, such as Java, we may not know the most precise type of value until +runtime. In the case of Java, this is ok because (almost) all variables are +reference values anyway (i.e. pointers to a heap allocated object). This +flexibility comes at the cost of performance, since all accesses to an object +must dereference a pointer.

+

Rust takes a different approach: it monomorphizes all generic types. This +means that compiler stamps out a different copy of the code of a generic +function for each concrete type needed. For example, if I use a Vec<u64> and +a Vec<String> in my code, then the generated binary will have two copies of +the generated code for Vec: one for Vec<u64> and another for Vec<String>. +The result is fast programs, but it comes at the cost of compile time (creating +all those copies can take a while) and binary size (all those copies might take +a lot of space).

+

Monomorphization is the first step in the backend of the Rust compiler.

+

Collection

+

First, we need to figure out what concrete types we need for all the generic +things in our program. This is called collection, and the code that does this +is called the monomorphization collector.

+

Take this example:

+
fn banana() {
+   peach::<u64>();
+}
+
+fn main() {
+    banana();
+}
+
+

The monomorphization collector will give you a list of [main, banana, peach::<u64>]. These are the functions that will have machine code generated +for them. Collector will also add things like statics to that list.

+

See the collector rustdocs for more info.

+

The monomorphization collector is run just before MIR lowering and codegen. +rustc_codegen_ssa::base::codegen_crate calls the +collect_and_partition_mono_items query, which does monomorphization +collection and then partitions them into codegen +units.

+

Codegen Unit (CGU) partitioning

+

For better incremental build times, the CGU partitioner creates two CGU for each source level +modules. One is for "stable" i.e. non-generic code and the other is more volatile code i.e. +monomorphized/specialized instances.

+

For dependencies, consider Crate A and Crate B, such that Crate B depends on Crate A. +The following table lists different scenarios for a function in Crate A that might be used by one +or more modules in Crate B.

+
+ + + + +
Crate A functionBehavior
Non-generic functionCrate A function doesn't appear in any codegen units of Crate B
Non-generic #[inline] functionCrate A function appears within a single CGU of Crate B, and exists even after post-inlining stage
Generic functionRegardless of inlining, all monomorphized (specialized) functions
from Crate A appear within a single codegen unit for Crate B.
The codegen unit exists even after the post inlining stage.
Generic #[inline] function- same -
+
+

For more details about the partitioner read the module level documentation.

+

Polymorphization

+

As mentioned above, monomorphization produces fast code, but it comes at the +cost of compile time and binary size. MIR optimizations can help a +bit with this.

+

In addition to MIR optimizations, rustc attempts to determine when fewer +copies of functions are necessary and avoid making those copies - known +as "polymorphization". When a function-like item is found during +monomorphization collection, the +rustc_mir_monomorphize::polymorphize::unused_generic_params +query is invoked, which traverses the MIR of the item to determine on which +generic parameters the item might not need duplicated.

+

Currently, polymorphization only looks for unused generic parameters. These +are relatively rare in functions, but closures inherit the generic +parameters of their parent function and it is common for closures to not +use those inherited parameters. Without polymorphization, a copy of these +closures would be created for each copy of the parent function. By +creating fewer copies, less LLVM IR is generated; therefore less needs to be processed.

+

unused_generic_params returns a FiniteBitSet<u64> where a bit is set if +the generic parameter of the corresponding index is unused. Any parameters +after the first sixty-four are considered used.

+

The results of polymorphization analysis are used in the +Instance::polymorphize function to replace the +Instance's substitutions for the unused generic parameters with their +identity substitutions.

+

Consider the example below:

+
fn foo<A, B>() {
+    let x: Option<B> = None;
+}
+
+fn main() {
+    foo::<u16, u32>();
+    foo::<u64, u32>();
+}
+
+

During monomorphization collection, foo will be collected with the +substitutions [u16, u32] and [u64, u32] (from its invocations in main). +foo has the identity substitutions [A, B] (or +[ty::Param(0), ty::Param(1)]).

+

Polymorphization will identify A as being unused and it will be replaced in +the substitutions with the identity parameter before being added to the set +of collected items - thereby reducing the copies from two ([u16, u32] and +[u64, u32]) to one ([A, u32]).

+

unused_generic_params will also be invoked during code generation when the +symbol name for foo is being computed for use in the callsites of foo +(which have the regular substitutions present, otherwise there would be a +symbol mismatch between the caller and the function).

+

As a result of polymorphization, items collected during monomorphization +cannot be assumed to be monomorphic.

+

It is intended that polymorphization be extended to more advanced cases, +such as where only the size/alignment of a generic parameter are required.

+

More details on polymorphization are available in the +master's thesis associated with polymorphization's initial +implementation.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/updating-llvm.html b/backend/updating-llvm.html new file mode 100644 index 000000000..d073df9dc --- /dev/null +++ b/backend/updating-llvm.html @@ -0,0 +1,436 @@ + + + + + + Updating LLVM - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Updating LLVM

+ + +

Rust supports building against multiple LLVM versions:

+
    +
  • Tip-of-tree for the current LLVM development branch is usually supported +within a few days. PRs for such fixes are tagged with llvm-main.
  • +
  • The latest released major version is always supported.
  • +
  • The one or two preceding major versions are usually supported.
  • +
+

By default, Rust uses its own fork in the rust-lang/llvm-project repository. +This fork is based on a release/$N.x branch of the upstream project, where +$N is either the latest released major version, or the current major version +in release candidate phase. The fork is never based on the main development +branch.

+

Our LLVM fork only accepts:

+
    +
  • Backports of changes that have already landed upstream.
  • +
  • Workarounds for build issues affecting our CI environment.
  • +
+

With the exception of one grandfathered-in patch for SGX enablement, we do not +accept functional patches that have not been upstreamed first.

+

There are three types of LLVM updates, with different procedures:

+
    +
  • Backports while the current major LLVM version is supported.
  • +
  • Backports while the current major LLVM version is no longer supported (or +the change is not eligible for upstream backport).
  • +
  • Update to a new major LLVM version.
  • +
+

Backports (upstream supported)

+

While the current major LLVM version is supported upstream, fixes should be +backported upstream first, and the release branch then merged back into the +Rust fork.

+
    +
  1. Make sure the bugfix is in upstream LLVM.
  2. +
  3. If this hasn't happened already, request a backport to the upstream release +branch. If you have LLVM commit access, follow the backport process. +Otherwise, open an issue requesting the backport. Continue once the +backport has been approved and merged.
  4. +
  5. Identify the branch that rustc is currently using. The src/llvm-project +submodule is always pinned to a branch of the +rust-lang/llvm-project repository.
  6. +
  7. Fork the rust-lang/llvm-project repository.
  8. +
  9. Check out the appropriate branch (typically named rustc/a.b-yyyy-mm-dd).
  10. +
  11. Add a remote for the upstream repository using +git remote add upstream https://github.com/llvm/llvm-project.git and +fetch it using git fetch upstream.
  12. +
  13. Merge the upstream/release/$N.x branch.
  14. +
  15. Push this branch to your fork.
  16. +
  17. Send a Pull Request to rust-lang/llvm-project to the same branch as before. +Be sure to reference the Rust and/or LLVM issue that you're fixing in the PR +description.
  18. +
  19. Wait for the PR to be merged.
  20. +
  21. Send a PR to rust-lang/rust updating the src/llvm-project submodule with +your bugfix. This can be done locally with git submodule update --remote src/llvm-project typically.
  22. +
  23. Wait for PR to be merged.
  24. +
+

An example PR: +#59089

+

Backports (upstream not supported)

+

Upstream LLVM releases are only supported for two to three months after the +GA release. Once upstream backports are no longer accepted, changes should be +cherry-picked directly to our fork.

+
    +
  1. Make sure the bugfix is in upstream LLVM.
  2. +
  3. Identify the branch that rustc is currently using. The src/llvm-project +submodule is always pinned to a branch of the +rust-lang/llvm-project repository.
  4. +
  5. Fork the rust-lang/llvm-project repository.
  6. +
  7. Check out the appropriate branch (typically named rustc/a.b-yyyy-mm-dd).
  8. +
  9. Add a remote for the upstream repository using +git remote add upstream https://github.com/llvm/llvm-project.git and +fetch it using git fetch upstream.
  10. +
  11. Cherry-pick the relevant commit(s) using git cherry-pick -x.
  12. +
  13. Push this branch to your fork.
  14. +
  15. Send a Pull Request to rust-lang/llvm-project to the same branch as before. +Be sure to reference the Rust and/or LLVM issue that you're fixing in the PR +description.
  16. +
  17. Wait for the PR to be merged.
  18. +
  19. Send a PR to rust-lang/rust updating the src/llvm-project submodule with +your bugfix. This can be done locally with git submodule update --remote src/llvm-project typically.
  20. +
  21. Wait for PR to be merged.
  22. +
+

An example PR: +#59089

+

New LLVM Release Updates

+ +

Unlike bugfixes, +updating to a new release of LLVM typically requires a lot more work. +This is where we can't reasonably cherry-pick commits backwards, +so we need to do a full update. +There's a lot of stuff to do here, +so let's go through each in detail.

+
    +
  1. +

    LLVM announces that its latest release version has branched. +This will show up as a branch in the llvm/llvm-project repository, +typically named release/$N.x, +where $N is the version of LLVM that's being released.

    +
  2. +
  3. +

    Create a new branch in the rust-lang/llvm-project repository +from this release/$N.x branch, +and name it rustc/a.b-yyyy-mm-dd, +where a.b is the current version number of LLVM in-tree +at the time of the branch, +and the remaining part is the current date.

    +
  4. +
  5. +

    Apply Rust-specific patches to the llvm-project repository. +All features and bugfixes are upstream, +but there's often some weird build-related patches +that don't make sense to upstream. +These patches are typically the latest patches in the +rust-lang/llvm-project branch that rustc is currently using.

    +
  6. +
  7. +

    Build the new LLVM in the rust repository. +To do this, +you'll want to update the src/llvm-project repository to your branch, +and the revision you've created. +It's also typically a good idea to update .gitmodules with the new +branch name of the LLVM submodule. +Make sure you've committed changes to +src/llvm-project to ensure submodule updates aren't reverted. +Some commands you should execute are:

    +
      +
    • ./x build src/llvm-project - test that LLVM still builds
    • +
    • ./x build - build the rest of rustc
    • +
    +

    You'll likely need to update llvm-wrapper/*.cpp +to compile with updated LLVM bindings. +Note that you should use #ifdef and such to ensure +that the bindings still compile on older LLVM versions.

    +

    Note that profile = "compiler" and other defaults set by ./x setup +download LLVM from CI instead of building it from source. +You should disable this temporarily to make sure your changes are being used. +This is done by having the following setting in config.toml:

    +
    [llvm]
    +download-ci-llvm = false
    +
    +
  8. +
  9. +

    Test for regressions across other platforms. LLVM often has at least one bug +for non-tier-1 architectures, so it's good to do some more testing before +sending this to bors! If you're low on resources you can send the PR as-is +now to bors, though, and it'll get tested anyway.

    +

    Ideally, build LLVM and test it on a few platforms:

    +
      +
    • Linux
    • +
    • macOS
    • +
    • Windows
    • +
    +

    Afterwards, run some docker containers that CI also does:

    +
      +
    • ./src/ci/docker/run.sh wasm32
    • +
    • ./src/ci/docker/run.sh arm-android
    • +
    • ./src/ci/docker/run.sh dist-various-1
    • +
    • ./src/ci/docker/run.sh dist-various-2
    • +
    • ./src/ci/docker/run.sh armhf-gnu
    • +
    +
  10. +
  11. +

    Prepare a PR to rust-lang/rust. Work with maintainers of +rust-lang/llvm-project to get your commit in a branch of that repository, +and then you can send a PR to rust-lang/rust. You'll change at least +src/llvm-project and will likely also change llvm-wrapper as well.

    + +
    +

    For prior art, here are some previous LLVM updates:

    + +
    +

    Note that sometimes it's easiest to land llvm-wrapper compatibility as a PR +before actually updating src/llvm-project. +This way, +while you're working through LLVM issues, +others interested in trying out the new LLVM can benefit from work you've done +to update the C++ bindings.

    +
  12. +
  13. +

    Over the next few months, +LLVM will continually push commits to its release/a.b branch. +We will often want to have those bug fixes as well. +The merge process for that is to use git merge itself to merge LLVM's +release/a.b branch with the branch created in step 2. +This is typically +done multiple times when necessary while LLVM's release branch is baking.

    +
  14. +
  15. +

    LLVM then announces the release of version a.b.

    +
  16. +
  17. +

    After LLVM's official release, +we follow the process of creating a new branch on the +rust-lang/llvm-project repository again, +this time with a new date. +It is only then that the PR to update Rust to use that version is merged.

    +

    The commit history of rust-lang/llvm-project +should look much cleaner as a git rebase is done, +where just a few Rust-specific commits are stacked on top of stock LLVM's release branch.

    +
  18. +
+

Caveats and gotchas

+

Ideally the above instructions are pretty smooth, but here's some caveats to +keep in mind while going through them:

+
    +
  • LLVM bugs are hard to find, don't hesitate to ask for help! +Bisection is definitely your friend here +(yes LLVM takes forever to build, yet bisection is still your friend). +Note that you can make use of Dev Desktops, +which is an initiative to provide the contributors with remote access to powerful hardware.
  • +
  • If you've got general questions, wg-llvm can help you out.
  • +
  • Creating branches is a privileged operation on GitHub, so you'll need someone +with write access to create the branches for you most likely.
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/book.js b/book.js new file mode 100644 index 000000000..d40440c72 --- /dev/null +++ b/book.js @@ -0,0 +1,679 @@ +"use strict"; + +// Fix back button cache problem +window.onunload = function () { }; + +// Global variable, shared between modules +function playground_text(playground) { + let code_block = playground.querySelector("code"); + + if (window.ace && code_block.classList.contains("editable")) { + let editor = window.ace.edit(code_block); + return editor.getValue(); + } else { + return code_block.textContent; + } +} + +(function codeSnippets() { + function fetch_with_timeout(url, options, timeout = 6000) { + return Promise.race([ + fetch(url, options), + new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout)) + ]); + } + + var playgrounds = Array.from(document.querySelectorAll(".playground")); + if (playgrounds.length > 0) { + fetch_with_timeout("https://play.rust-lang.org/meta/crates", { + headers: { + 'Content-Type': "application/json", + }, + method: 'POST', + mode: 'cors', + }) + .then(response => response.json()) + .then(response => { + // get list of crates available in the rust playground + let playground_crates = response.crates.map(item => item["id"]); + playgrounds.forEach(block => handle_crate_list_update(block, playground_crates)); + }); + } + + function handle_crate_list_update(playground_block, playground_crates) { + // update the play buttons after receiving the response + update_play_button(playground_block, playground_crates); + + // and install on change listener to dynamically update ACE editors + if (window.ace) { + let code_block = playground_block.querySelector("code"); + if (code_block.classList.contains("editable")) { + let editor = window.ace.edit(code_block); + editor.addEventListener("change", function (e) { + update_play_button(playground_block, playground_crates); + }); + // add Ctrl-Enter command to execute rust code + editor.commands.addCommand({ + name: "run", + bindKey: { + win: "Ctrl-Enter", + mac: "Ctrl-Enter" + }, + exec: _editor => run_rust_code(playground_block) + }); + } + } + } + + // updates the visibility of play button based on `no_run` class and + // used crates vs ones available on http://play.rust-lang.org + function update_play_button(pre_block, playground_crates) { + var play_button = pre_block.querySelector(".play-button"); + + // skip if code is `no_run` + if (pre_block.querySelector('code').classList.contains("no_run")) { + play_button.classList.add("hidden"); + return; + } + + // get list of `extern crate`'s from snippet + var txt = playground_text(pre_block); + var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g; + var snippet_crates = []; + var item; + while (item = re.exec(txt)) { + snippet_crates.push(item[1]); + } + + // check if all used crates are available on play.rust-lang.org + var all_available = snippet_crates.every(function (elem) { + return playground_crates.indexOf(elem) > -1; + }); + + if (all_available) { + play_button.classList.remove("hidden"); + } else { + play_button.classList.add("hidden"); + } + } + + function run_rust_code(code_block) { + var result_block = code_block.querySelector(".result"); + if (!result_block) { + result_block = document.createElement('code'); + result_block.className = 'result hljs language-bash'; + + code_block.append(result_block); + } + + let text = playground_text(code_block); + let classes = code_block.querySelector('code').classList; + let edition = "2015"; + if(classes.contains("edition2018")) { + edition = "2018"; + } else if(classes.contains("edition2021")) { + edition = "2021"; + } + var params = { + version: "stable", + optimize: "0", + code: text, + edition: edition + }; + + if (text.indexOf("#![feature") !== -1) { + params.version = "nightly"; + } + + result_block.innerText = "Running..."; + + fetch_with_timeout("https://play.rust-lang.org/evaluate.json", { + headers: { + 'Content-Type': "application/json", + }, + method: 'POST', + mode: 'cors', + body: JSON.stringify(params) + }) + .then(response => response.json()) + .then(response => { + if (response.result.trim() === '') { + result_block.innerText = "No output"; + result_block.classList.add("result-no-output"); + } else { + result_block.innerText = response.result; + result_block.classList.remove("result-no-output"); + } + }) + .catch(error => result_block.innerText = "Playground Communication: " + error.message); + } + + // Syntax highlighting Configuration + hljs.configure({ + tabReplace: ' ', // 4 spaces + languages: [], // Languages used for auto-detection + }); + + let code_nodes = Array + .from(document.querySelectorAll('code')) + // Don't highlight `inline code` blocks in headers. + .filter(function (node) {return !node.parentElement.classList.contains("header"); }); + + if (window.ace) { + // language-rust class needs to be removed for editable + // blocks or highlightjs will capture events + code_nodes + .filter(function (node) {return node.classList.contains("editable"); }) + .forEach(function (block) { block.classList.remove('language-rust'); }); + + Array + code_nodes + .filter(function (node) {return !node.classList.contains("editable"); }) + .forEach(function (block) { hljs.highlightBlock(block); }); + } else { + code_nodes.forEach(function (block) { hljs.highlightBlock(block); }); + } + + // Adding the hljs class gives code blocks the color css + // even if highlighting doesn't apply + code_nodes.forEach(function (block) { block.classList.add('hljs'); }); + + Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) { + + var lines = Array.from(block.querySelectorAll('.boring')); + // If no lines were hidden, return + if (!lines.length) { return; } + block.classList.add("hide-boring"); + + var buttons = document.createElement('div'); + buttons.className = 'buttons'; + buttons.innerHTML = ""; + + // add expand button + var pre_block = block.parentNode; + pre_block.insertBefore(buttons, pre_block.firstChild); + + pre_block.querySelector('.buttons').addEventListener('click', function (e) { + if (e.target.classList.contains('fa-eye')) { + e.target.classList.remove('fa-eye'); + e.target.classList.add('fa-eye-slash'); + e.target.title = 'Hide lines'; + e.target.setAttribute('aria-label', e.target.title); + + block.classList.remove('hide-boring'); + } else if (e.target.classList.contains('fa-eye-slash')) { + e.target.classList.remove('fa-eye-slash'); + e.target.classList.add('fa-eye'); + e.target.title = 'Show hidden lines'; + e.target.setAttribute('aria-label', e.target.title); + + block.classList.add('hide-boring'); + } + }); + }); + + if (window.playground_copyable) { + Array.from(document.querySelectorAll('pre code')).forEach(function (block) { + var pre_block = block.parentNode; + if (!pre_block.classList.contains('playground')) { + var buttons = pre_block.querySelector(".buttons"); + if (!buttons) { + buttons = document.createElement('div'); + buttons.className = 'buttons'; + pre_block.insertBefore(buttons, pre_block.firstChild); + } + + var clipButton = document.createElement('button'); + clipButton.className = 'fa fa-copy clip-button'; + clipButton.title = 'Copy to clipboard'; + clipButton.setAttribute('aria-label', clipButton.title); + clipButton.innerHTML = ''; + + buttons.insertBefore(clipButton, buttons.firstChild); + } + }); + } + + // Process playground code blocks + Array.from(document.querySelectorAll(".playground")).forEach(function (pre_block) { + // Add play button + var buttons = pre_block.querySelector(".buttons"); + if (!buttons) { + buttons = document.createElement('div'); + buttons.className = 'buttons'; + pre_block.insertBefore(buttons, pre_block.firstChild); + } + + var runCodeButton = document.createElement('button'); + runCodeButton.className = 'fa fa-play play-button'; + runCodeButton.hidden = true; + runCodeButton.title = 'Run this code'; + runCodeButton.setAttribute('aria-label', runCodeButton.title); + + buttons.insertBefore(runCodeButton, buttons.firstChild); + runCodeButton.addEventListener('click', function (e) { + run_rust_code(pre_block); + }); + + if (window.playground_copyable) { + var copyCodeClipboardButton = document.createElement('button'); + copyCodeClipboardButton.className = 'fa fa-copy clip-button'; + copyCodeClipboardButton.innerHTML = ''; + copyCodeClipboardButton.title = 'Copy to clipboard'; + copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title); + + buttons.insertBefore(copyCodeClipboardButton, buttons.firstChild); + } + + let code_block = pre_block.querySelector("code"); + if (window.ace && code_block.classList.contains("editable")) { + var undoChangesButton = document.createElement('button'); + undoChangesButton.className = 'fa fa-history reset-button'; + undoChangesButton.title = 'Undo changes'; + undoChangesButton.setAttribute('aria-label', undoChangesButton.title); + + buttons.insertBefore(undoChangesButton, buttons.firstChild); + + undoChangesButton.addEventListener('click', function () { + let editor = window.ace.edit(code_block); + editor.setValue(editor.originalCode); + editor.clearSelection(); + }); + } + }); +})(); + +(function themes() { + var html = document.querySelector('html'); + var themeToggleButton = document.getElementById('theme-toggle'); + var themePopup = document.getElementById('theme-list'); + var themeColorMetaTag = document.querySelector('meta[name="theme-color"]'); + var stylesheets = { + ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"), + tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"), + highlight: document.querySelector("[href$='highlight.css']"), + }; + + function showThemes() { + themePopup.style.display = 'block'; + themeToggleButton.setAttribute('aria-expanded', true); + themePopup.querySelector("button#" + get_theme()).focus(); + } + + function hideThemes() { + themePopup.style.display = 'none'; + themeToggleButton.setAttribute('aria-expanded', false); + themeToggleButton.focus(); + } + + function get_theme() { + var theme; + try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { } + if (theme === null || theme === undefined) { + return default_theme; + } else { + return theme; + } + } + + function set_theme(theme, store = true) { + let ace_theme; + + if (theme == 'coal' || theme == 'navy') { + stylesheets.ayuHighlight.disabled = true; + stylesheets.tomorrowNight.disabled = false; + stylesheets.highlight.disabled = true; + + ace_theme = "ace/theme/tomorrow_night"; + } else if (theme == 'ayu') { + stylesheets.ayuHighlight.disabled = false; + stylesheets.tomorrowNight.disabled = true; + stylesheets.highlight.disabled = true; + ace_theme = "ace/theme/tomorrow_night"; + } else { + stylesheets.ayuHighlight.disabled = true; + stylesheets.tomorrowNight.disabled = true; + stylesheets.highlight.disabled = false; + ace_theme = "ace/theme/dawn"; + } + + setTimeout(function () { + themeColorMetaTag.content = getComputedStyle(document.body).backgroundColor; + }, 1); + + if (window.ace && window.editors) { + window.editors.forEach(function (editor) { + editor.setTheme(ace_theme); + }); + } + + var previousTheme = get_theme(); + + if (store) { + try { localStorage.setItem('mdbook-theme', theme); } catch (e) { } + } + + html.classList.remove(previousTheme); + html.classList.add(theme); + } + + // Set theme + var theme = get_theme(); + + set_theme(theme, false); + + themeToggleButton.addEventListener('click', function () { + if (themePopup.style.display === 'block') { + hideThemes(); + } else { + showThemes(); + } + }); + + themePopup.addEventListener('click', function (e) { + var theme; + if (e.target.className === "theme") { + theme = e.target.id; + } else if (e.target.parentElement.className === "theme") { + theme = e.target.parentElement.id; + } else { + return; + } + set_theme(theme); + }); + + themePopup.addEventListener('focusout', function(e) { + // e.relatedTarget is null in Safari and Firefox on macOS (see workaround below) + if (!!e.relatedTarget && !themeToggleButton.contains(e.relatedTarget) && !themePopup.contains(e.relatedTarget)) { + hideThemes(); + } + }); + + // Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628 + document.addEventListener('click', function(e) { + if (themePopup.style.display === 'block' && !themeToggleButton.contains(e.target) && !themePopup.contains(e.target)) { + hideThemes(); + } + }); + + document.addEventListener('keydown', function (e) { + if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; } + if (!themePopup.contains(e.target)) { return; } + + switch (e.key) { + case 'Escape': + e.preventDefault(); + hideThemes(); + break; + case 'ArrowUp': + e.preventDefault(); + var li = document.activeElement.parentElement; + if (li && li.previousElementSibling) { + li.previousElementSibling.querySelector('button').focus(); + } + break; + case 'ArrowDown': + e.preventDefault(); + var li = document.activeElement.parentElement; + if (li && li.nextElementSibling) { + li.nextElementSibling.querySelector('button').focus(); + } + break; + case 'Home': + e.preventDefault(); + themePopup.querySelector('li:first-child button').focus(); + break; + case 'End': + e.preventDefault(); + themePopup.querySelector('li:last-child button').focus(); + break; + } + }); +})(); + +(function sidebar() { + var html = document.querySelector("html"); + var sidebar = document.getElementById("sidebar"); + var sidebarLinks = document.querySelectorAll('#sidebar a'); + var sidebarToggleButton = document.getElementById("sidebar-toggle"); + var sidebarResizeHandle = document.getElementById("sidebar-resize-handle"); + var firstContact = null; + + function showSidebar() { + html.classList.remove('sidebar-hidden') + html.classList.add('sidebar-visible'); + Array.from(sidebarLinks).forEach(function (link) { + link.setAttribute('tabIndex', 0); + }); + sidebarToggleButton.setAttribute('aria-expanded', true); + sidebar.setAttribute('aria-hidden', false); + try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { } + } + + + var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle'); + + function toggleSection(ev) { + ev.currentTarget.parentElement.classList.toggle('expanded'); + } + + Array.from(sidebarAnchorToggles).forEach(function (el) { + el.addEventListener('click', toggleSection); + }); + + function hideSidebar() { + html.classList.remove('sidebar-visible') + html.classList.add('sidebar-hidden'); + Array.from(sidebarLinks).forEach(function (link) { + link.setAttribute('tabIndex', -1); + }); + sidebarToggleButton.setAttribute('aria-expanded', false); + sidebar.setAttribute('aria-hidden', true); + try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { } + } + + // Toggle sidebar + sidebarToggleButton.addEventListener('click', function sidebarToggle() { + if (html.classList.contains("sidebar-hidden")) { + var current_width = parseInt( + document.documentElement.style.getPropertyValue('--sidebar-width'), 10); + if (current_width < 150) { + document.documentElement.style.setProperty('--sidebar-width', '150px'); + } + showSidebar(); + } else if (html.classList.contains("sidebar-visible")) { + hideSidebar(); + } else { + if (getComputedStyle(sidebar)['transform'] === 'none') { + hideSidebar(); + } else { + showSidebar(); + } + } + }); + + sidebarResizeHandle.addEventListener('mousedown', initResize, false); + + function initResize(e) { + window.addEventListener('mousemove', resize, false); + window.addEventListener('mouseup', stopResize, false); + html.classList.add('sidebar-resizing'); + } + function resize(e) { + var pos = (e.clientX - sidebar.offsetLeft); + if (pos < 20) { + hideSidebar(); + } else { + if (html.classList.contains("sidebar-hidden")) { + showSidebar(); + } + pos = Math.min(pos, window.innerWidth - 100); + document.documentElement.style.setProperty('--sidebar-width', pos + 'px'); + } + } + //on mouseup remove windows functions mousemove & mouseup + function stopResize(e) { + html.classList.remove('sidebar-resizing'); + window.removeEventListener('mousemove', resize, false); + window.removeEventListener('mouseup', stopResize, false); + } + + document.addEventListener('touchstart', function (e) { + firstContact = { + x: e.touches[0].clientX, + time: Date.now() + }; + }, { passive: true }); + + document.addEventListener('touchmove', function (e) { + if (!firstContact) + return; + + var curX = e.touches[0].clientX; + var xDiff = curX - firstContact.x, + tDiff = Date.now() - firstContact.time; + + if (tDiff < 250 && Math.abs(xDiff) >= 150) { + if (xDiff >= 0 && firstContact.x < Math.min(document.body.clientWidth * 0.25, 300)) + showSidebar(); + else if (xDiff < 0 && curX < 300) + hideSidebar(); + + firstContact = null; + } + }, { passive: true }); + + // Scroll sidebar to current active section + var activeSection = document.getElementById("sidebar").querySelector(".active"); + if (activeSection) { + // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView + activeSection.scrollIntoView({ block: 'center' }); + } +})(); + +(function chapterNavigation() { + document.addEventListener('keydown', function (e) { + if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; } + if (window.search && window.search.hasFocus()) { return; } + + switch (e.key) { + case 'ArrowRight': + e.preventDefault(); + var nextButton = document.querySelector('.nav-chapters.next'); + if (nextButton) { + window.location.href = nextButton.href; + } + break; + case 'ArrowLeft': + e.preventDefault(); + var previousButton = document.querySelector('.nav-chapters.previous'); + if (previousButton) { + window.location.href = previousButton.href; + } + break; + } + }); +})(); + +(function clipboard() { + var clipButtons = document.querySelectorAll('.clip-button'); + + function hideTooltip(elem) { + elem.firstChild.innerText = ""; + elem.className = 'fa fa-copy clip-button'; + } + + function showTooltip(elem, msg) { + elem.firstChild.innerText = msg; + elem.className = 'fa fa-copy tooltipped'; + } + + var clipboardSnippets = new ClipboardJS('.clip-button', { + text: function (trigger) { + hideTooltip(trigger); + let playground = trigger.closest("pre"); + return playground_text(playground); + } + }); + + Array.from(clipButtons).forEach(function (clipButton) { + clipButton.addEventListener('mouseout', function (e) { + hideTooltip(e.currentTarget); + }); + }); + + clipboardSnippets.on('success', function (e) { + e.clearSelection(); + showTooltip(e.trigger, "Copied!"); + }); + + clipboardSnippets.on('error', function (e) { + showTooltip(e.trigger, "Clipboard error!"); + }); +})(); + +(function scrollToTop () { + var menuTitle = document.querySelector('.menu-title'); + + menuTitle.addEventListener('click', function () { + document.scrollingElement.scrollTo({ top: 0, behavior: 'smooth' }); + }); +})(); + +(function controllMenu() { + var menu = document.getElementById('menu-bar'); + + (function controllPosition() { + var scrollTop = document.scrollingElement.scrollTop; + var prevScrollTop = scrollTop; + var minMenuY = -menu.clientHeight - 50; + // When the script loads, the page can be at any scroll (e.g. if you reforesh it). + menu.style.top = scrollTop + 'px'; + // Same as parseInt(menu.style.top.slice(0, -2), but faster + var topCache = menu.style.top.slice(0, -2); + menu.classList.remove('sticky'); + var stickyCache = false; // Same as menu.classList.contains('sticky'), but faster + document.addEventListener('scroll', function () { + scrollTop = Math.max(document.scrollingElement.scrollTop, 0); + // `null` means that it doesn't need to be updated + var nextSticky = null; + var nextTop = null; + var scrollDown = scrollTop > prevScrollTop; + var menuPosAbsoluteY = topCache - scrollTop; + if (scrollDown) { + nextSticky = false; + if (menuPosAbsoluteY > 0) { + nextTop = prevScrollTop; + } + } else { + if (menuPosAbsoluteY > 0) { + nextSticky = true; + } else if (menuPosAbsoluteY < minMenuY) { + nextTop = prevScrollTop + minMenuY; + } + } + if (nextSticky === true && stickyCache === false) { + menu.classList.add('sticky'); + stickyCache = true; + } else if (nextSticky === false && stickyCache === true) { + menu.classList.remove('sticky'); + stickyCache = false; + } + if (nextTop !== null) { + menu.style.top = nextTop + 'px'; + topCache = nextTop; + } + prevScrollTop = scrollTop; + }, { passive: true }); + })(); + (function controllBorder() { + menu.classList.remove('bordered'); + document.addEventListener('scroll', function () { + if (menu.offsetTop === 0) { + menu.classList.remove('bordered'); + } else { + menu.classList.add('bordered'); + } + }, { passive: true }); + })(); +})(); diff --git a/borrow_check.html b/borrow_check.html new file mode 100644 index 000000000..82468d673 --- /dev/null +++ b/borrow_check.html @@ -0,0 +1,253 @@ + + + + + + The borrow checker - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

MIR borrow check

+

The borrow check is Rust's "secret sauce" – it is tasked with +enforcing a number of properties:

+
    +
  • That all variables are initialized before they are used.
  • +
  • That you can't move the same value twice.
  • +
  • That you can't move a value while it is borrowed.
  • +
  • That you can't access a place while it is mutably borrowed (except through +the reference).
  • +
  • That you can't mutate a place while it is immutably borrowed.
  • +
  • etc
  • +
+

The borrow checker operates on the MIR. An older implementation operated on the +HIR. Doing borrow checking on MIR has several advantages:

+ +

Major phases of the borrow checker

+

The borrow checker source is found in +the rustc_borrowck crate. The main entry point is +the mir_borrowck query.

+
    +
  • We first create a local copy of the MIR. In the coming steps, +we will modify this copy in place to modify the types and things to +include references to the new regions that we are computing.
  • +
  • We then invoke replace_regions_in_mir to modify our local MIR. +Among other things, this function will replace all of the regions +in the MIR with fresh inference variables.
  • +
  • Next, we perform a number of +dataflow analyses that +compute what data is moved and when.
  • +
  • We then do a second type check across the MIR: +the purpose of this type check is to determine all of the constraints between +different regions.
  • +
  • Next, we do region inference, which computes +the values of each region — basically, the points in the control-flow graph where +each lifetime must be valid according to the constraints we collected.
  • +
  • At this point, we can compute the "borrows in scope" at each point.
  • +
  • Finally, we do a second walk over the MIR, looking at the actions it +does and reporting errors. For example, if we see a statement like +*a + 1, then we would check that the variable a is initialized +and that it is not mutably borrowed, as either of those would +require an error to be reported. Doing this check requires the results of all +the previous analyses.
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/drop_check.html b/borrow_check/drop_check.html new file mode 100644 index 000000000..a37d406b8 --- /dev/null +++ b/borrow_check/drop_check.html @@ -0,0 +1,346 @@ + + + + + + Drop check - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Drop Check

+

We generally require the type of locals to be well-formed whenever the +local is used. This includes proving the where-bounds of the local and +also requires all regions used by it to be live.

+

The only exception to this is when implicitly dropping values when they +go out of scope. This does not necessarily require the value to be live:

+
fn main() {
+    let x = vec![];
+    {
+        let y = String::from("I am temporary");
+        x.push(&y);
+    }
+    // `x` goes out of scope here, after the reference to `y`
+    // is invalidated. This means that while dropping `x` its type
+    // is not well-formed as it contain regions which are not live.
+}
+
+

This is only sound if dropping the value does not try to access any dead +region. We check this by requiring the type of the value to be +drop-live. +The requirements for which are computed in fn dropck_outlives.

+

The rest of this section uses the following type definition for a type +which requires its region parameter to be live:

+
#![allow(unused)]
+fn main() {
+struct PrintOnDrop<'a>(&'a str);
+impl<'a> Drop for PrintOnDrop<'_> {
+    fn drop(&mut self) {
+        println!("{}", self.0);
+    }
+}
+}
+
+

How values are dropped

+

At its core, a value of type T is dropped by executing its "drop +glue". Drop glue is compiler generated and first calls <T as Drop>::drop and then recursively calls the drop glue of any recursively +owned values.

+
    +
  • If T has an explicit Drop impl, call <T as Drop>::drop.
  • +
  • Regardless of whether T implements Drop, recurse into all values +owned by T: +
      +
    • references, raw pointers, function pointers, function items, trait +objects1, and scalars do not own anything.
    • +
    • tuples, slices, and arrays consider their elements to be owned. +For arrays of length zero we do not own any value of the element +type.
    • +
    • all fields (of all variants) of ADTs are considered owned. We +consider all variants for enums. The exception here is +ManuallyDrop<U> which is not considered to own U. +PhantomData<U> also does not own anything. +closures and generators own their captured upvars.
    • +
    +
  • +
+

Whether a type has drop glue is returned by fn Ty::needs_drop.

+

Partially dropping a local

+

For types which do not implement Drop themselves, we can also +partially move parts of the value before dropping the rest. In this case +only the drop glue for the not-yet moved values is called, e.g.

+
fn main() {
+    let mut x = (PrintOnDrop("third"), PrintOnDrop("first"));
+    drop(x.1);
+    println!("second")
+}
+
+

During MIR building we assume that a local may get dropped whenever it +goes out of scope as long as its type needs drop. Computing the exact +drop glue for a variable happens after borrowck in the +ElaborateDrops pass. This means that even if some part of the local +have been dropped previously, dropck still requires this value to be +live. This is the case even if we completely moved a local.

+
fn main() {
+    let mut x;
+    {
+        let temp = String::from("I am temporary");
+        x = PrintOnDrop(&temp);
+        drop(x);
+    }
+} //~ ERROR `temp` does not live long enough.
+
+

It should be possible to add some amount of drop elaboration before +borrowck, allowing this example to compile. There is an unstable feature +to move drop elaboration before const checking: +#73255. Such a feature +gate does not exist for doing some drop elaboration before borrowck, +although there's a relevant +MCP.

+
1 +

you can consider trait objects to have a builtin Drop +implementation which directly uses the drop_in_place provided by the +vtable. This Drop implementation requires all its generic parameters +to be live.

+
+

dropck_outlives

+

There are two distinct "liveness" computations that we perform:

+
    +
  • a value v is use-live at location L if it may be "used" later; a +use here is basically anything that is not a drop
  • +
  • a value v is drop-live at location L if it maybe dropped later
  • +
+

When things are use-live, their entire type must be valid at L. When +they are drop-live, all regions that are required by dropck must be +valid at L. The values dropped in the MIR are places.

+

The constraints computed by dropck_outlives for a type closely match +the generated drop glue for that type. Unlike drop glue, +dropck_outlives cares about the types of owned values, not the values +itself. For a value of type T

+
    +
  • if T has an explicit Drop, require all generic arguments to be +live, unless they are marked with #[may_dangle] in which case they +are fully ignored
  • +
  • regardless of whether T has an explicit Drop, recurse into all +types owned by T +
      +
    • references, raw pointers, function pointers, function items, trait +objects1, and scalars do not own anything.
    • +
    • tuples, slices and arrays consider their element type to be owned. +For arrays we currently do not check whether their length is +zero.
    • +
    • all fields (of all variants) of ADTs are considered owned. The +exception here is ManuallyDrop<U> which is not considered to own +U. We consider PhantomData<U> to own U.
    • +
    • closures and generators own their captured upvars.
    • +
    +
  • +
+

The sections marked in bold are cases where dropck_outlives considers +types to be owned which are ignored by Ty::needs_drop. We only rely on +dropck_outlives if Ty::needs_drop for the containing local returned +true.This means liveness requirements can change depending on whether +a type is contained in a larger local. This is inconsistent, and +should be fixed: an example for +arrays +and for +PhantomData.2

+

One possible way these inconsistencies can be fixed is by MIR building +to be more pessimistic, probably by making Ty::needs_drop weaker, or +alternatively, changing dropck_outlives to be more precise, requiring +fewer regions to be live.

+
2 +

This is the core assumption of #110288 and RFC 3417.

+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/moves_and_initialization.html b/borrow_check/moves_and_initialization.html new file mode 100644 index 000000000..27e723c04 --- /dev/null +++ b/borrow_check/moves_and_initialization.html @@ -0,0 +1,245 @@ + + + + + + Tracking moves and initialization - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Tracking moves and initialization

+

Part of the borrow checker's job is to track which variables are +"initialized" at any given point in time -- this also requires +figuring out where moves occur and tracking those.

+

Initialization and moves

+

From a user's perspective, initialization -- giving a variable some +value -- and moves -- transferring ownership to another place -- might +seem like distinct topics. Indeed, our borrow checker error messages +often talk about them differently. But within the borrow checker, +they are not nearly as separate. Roughly speaking, the borrow checker +tracks the set of "initialized places" at any point in the source +code. Assigning to a previously uninitialized local variable adds it +to that set; moving from a local variable removes it from that set.

+

Consider this example:

+
fn foo() {
+    let a: Vec<u32>;
+    
+    // a is not initialized yet
+    
+    a = vec![22];
+    
+    // a is initialized here
+    
+    std::mem::drop(a); // a is moved here
+    
+    // a is no longer initialized here
+
+    let l = a.len(); //~ ERROR
+}
+
+

Here you can see that a starts off as uninitialized; once it is +assigned, it becomes initialized. But when drop(a) is called, that +moves a into the call, and hence it becomes uninitialized again.

+

Subsections

+

To make it easier to peruse, this section is broken into a number of +subsections:

+
    +
  • Move paths the +move path concept that we use to track which local variables (or parts of +local variables, in some cases) are initialized.
  • +
  • TODO Rest not yet written =)
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/moves_and_initialization/move_paths.html b/borrow_check/moves_and_initialization/move_paths.html new file mode 100644 index 000000000..0a4b80369 --- /dev/null +++ b/borrow_check/moves_and_initialization/move_paths.html @@ -0,0 +1,301 @@ + + + + + + Move paths - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Move paths

+ +

In reality, it's not enough to track initialization at the granularity +of local variables. Rust also allows us to do moves and initialization +at the field granularity:

+
fn foo() {
+    let a: (Vec<u32>, Vec<u32>) = (vec![22], vec![44]);
+
+    // a.0 and a.1 are both initialized
+
+    let b = a.0; // moves a.0
+
+    // a.0 is not initialized, but a.1 still is
+
+    let c = a.0; // ERROR
+    let d = a.1; // OK
+}
+
+

To handle this, we track initialization at the granularity of a move +path. A MovePath represents some location that the user can +initialize, move, etc. So e.g. there is a move-path representing the +local variable a, and there is a move-path representing a.0. Move +paths roughly correspond to the concept of a Place from MIR, but +they are indexed in ways that enable us to do move analysis more +efficiently.

+

Move path indices

+

Although there is a MovePath data structure, they are never referenced +directly. Instead, all the code passes around indices of type +MovePathIndex. If you need to get information about a move path, you use +this index with the move_paths field of the MoveData. For +example, to convert a MovePathIndex mpi into a MIR Place, you might +access the MovePath::place field like so:

+
move_data.move_paths[mpi].place
+
+

Building move paths

+

One of the first things we do in the MIR borrow check is to construct +the set of move paths. This is done as part of the +MoveData::gather_moves function. This function uses a MIR visitor +called MoveDataBuilder to walk the MIR and look at how each Place +within is accessed. For each such Place, it constructs a +corresponding MovePathIndex. It also records when/where that +particular move path is moved/initialized, but we'll get to that in a +later section.

+

Illegal move paths

+

We don't actually create a move-path for every Place that gets +used. In particular, if it is illegal to move from a Place, then +there is no need for a MovePathIndex. Some examples:

+
    +
  • You cannot move from a static variable, so we do not create a MovePathIndex +for static variables.
  • +
  • You cannot move an individual element of an array, so if we have e.g. foo: [String; 3], +there would be no move-path for foo[1].
  • +
  • You cannot move from inside of a borrowed reference, so if we have e.g. foo: &String, +there would be no move-path for *foo.
  • +
+

These rules are enforced by the move_path_for function, which +converts a Place into a MovePathIndex -- in error cases like +those just discussed, the function returns an Err. This in turn +means we don't have to bother tracking whether those places are +initialized (which lowers overhead).

+

Looking up a move-path

+

If you have a Place and you would like to convert it to a MovePathIndex, you +can do that using the MovePathLookup structure found in the rev_lookup field +of MoveData. There are two different methods:

+
    +
  • find_local, which takes a mir::Local representing a local +variable. This is the easier method, because we always create a +MovePathIndex for every local variable.
  • +
  • find, which takes an arbitrary Place. This method is a bit +more annoying to use, precisely because we don't have a +MovePathIndex for every Place (as we just discussed in +the "illegal move paths" section). Therefore, find returns a +LookupResult indicating the closest path it was able to find +that exists (e.g., for foo[1], it might return just the path for +foo).
  • +
+

Cross-references

+

As we noted above, move-paths are stored in a big vector and +referenced via their MovePathIndex. However, within this vector, +they are also structured into a tree. So for example if you have the +MovePathIndex for a.b.c, you can go to its parent move-path +a.b. You can also iterate over all children paths: so, from a.b, +you might iterate to find the path a.b.c (here you are iterating +just over the paths that are actually referenced in the source, +not all possible paths that could have been referenced). These +references are used for example in the +find_in_move_path_or_its_descendants function, which determines +whether a move-path (e.g., a.b) or any child of that move-path +(e.g.,a.b.c) matches a given predicate.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/opaque-types-region-inference-restrictions.html b/borrow_check/opaque-types-region-inference-restrictions.html new file mode 100644 index 000000000..2f5348d33 --- /dev/null +++ b/borrow_check/opaque-types-region-inference-restrictions.html @@ -0,0 +1,452 @@ + + + + + + Region inference restrictions - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Opaque types region inference restrictions

+

In this chapter we discuss the various restrictions we impose on the generic arguments of +opaque types when defining their hidden types +Opaque<'a, 'b, .., A, B, ..> := SomeHiddenType.

+

These restrictions are implemented in borrow checking (Source) +as it is the final step opaque types inference.

+

Background: type and const generic arguments

+

For type arguments, two restrictions are necessary: each type argument must be +(1) a type parameter and +(2) is unique among the generic arguments. +The same is applied to const arguments.

+

Example of case (1):

+
#![allow(unused)]
+fn main() {
+type Opaque<X> = impl Sized;
+
+// `T` is a type parameter.
+// Opaque<T> := ();
+fn good<T>() -> Opaque<T> {}
+
+// `()` is not a type parameter.
+// Opaque<()> := ();
+fn bad() -> Opaque<()> {} //~ ERROR
+}
+
+

Example of case (2):

+
#![allow(unused)]
+fn main() {
+type Opaque<X, Y> = impl Sized;
+
+// `T` and `U` are unique in the generic args.
+// Opaque<T, U> := T;
+fn good<T, U>(t: T, _u: U) -> Opaque<T, U> { t }
+
+// `T` appears twice in the generic args.
+// Opaque<T, T> := T;
+fn bad<T>(t: T) -> Opaque<T, T> { t } //~ ERROR
+}
+
+

Motivation: In the first case Opaque<()> := (), the hidden type is ambiguous because +it is compatible with two different interpretaions: Opaque<X> := X and Opaque<X> := (). +Similarly for the second case Opaque<T, T> := T, it is ambiguous whether it should be +interpreted as Opaque<X, Y> := X or as Opaque<X, Y> := Y. +Because of this ambiguity, both cases are rejected as invalid defining uses.

+

Uniqueness restriction

+

Each lifetime argument must be unique in the arguments list and must not be 'static. +This is in order to avoid an ambiguity with hidden type inference similar to the case of +type parameters. +For example, the invalid defining use below Opaque<'static> := Inv<'static> is compatible with +both Opaque<'x> := Inv<'static> and Opaque<'x> := Inv<'x>.

+
#![allow(unused)]
+fn main() {
+type Opaque<'x> = impl Sized + 'x;
+type Inv<'a> = Option<*mut &'a ()>;
+
+fn good<'a>() -> Opaque<'a> { Inv::<'static>::None }
+
+fn bad() -> Opaque<'static> { Inv::<'static>::None }
+//~^ ERROR
+}
+
+
#![allow(unused)]
+fn main() {
+type Opaque<'x, 'y> = impl Trait<'x, 'y>;
+
+fn good<'a, 'b>() -> Opaque<'a, 'b> {}
+
+fn bad<'a>() -> Opaque<'a, 'a> {}
+//~^ ERROR
+}
+
+

Semantic lifetime equality: +One complexity with lifetimes compared to type parameters is that +two lifetimes that are syntactically different may be semantically equal. +Therefore, we need to be cautious when verifying that the lifetimes are unique.

+
#![allow(unused)]
+fn main() {
+// This is also invalid because `'a` is *semantically* equal to `'static`.
+fn still_bad_1<'a: 'static>() -> Opaque<'a> {}
+//~^ Should error!
+
+// This is also invalid because `'a` and `'b` are *semantically* equal.
+fn still_bad_2<'a: 'b, 'b: 'a>() -> Opaque<'a, 'b> {}
+//~^ Should error!
+}
+
+

An exception to uniqueness rule

+

An exception to the uniqueness rule above is when the bounds at the opaque type's definition require +a lifetime parameter to be equal to another one or to the 'static lifetime.

+
#![allow(unused)]
+fn main() {
+// The definition requires `'x` to be equal to `'static`.
+type Opaque<'x: 'static> = impl Sized + 'x;
+
+fn good() -> Opaque<'static> {}
+}
+
+

Motivation: an attempt to implement the uniqueness restriction for RPITs resulted in a +breakage found by crater. +This can be mitigated by this exception to the rule. +An example of the code that would otherwise break:

+
#![allow(unused)]
+fn main() {
+struct Type<'a>(&'a ());
+impl<'a> Type<'a> {
+    // `'b == 'a`
+    fn do_stuff<'b: 'a>(&'b self) -> impl Trait<'a, 'b> {}
+}
+}
+
+

Why this is correct: for such a defining use like Opaque<'a, 'a> := &'a str, +it can be interpreted in either way—either as Opaque<'x, 'y> := &'x str or as +Opaque<'x, 'y> := &'y str and it wouldn't matter because every use of Opaque +will guarantee that both parameters are equal as per the well-formedness rules.

+

Universal lifetimes restriction

+

Only universally quantified lifetimes are allowed in the opaque type arguments. +This includes lifetime parameters and placeholders.

+
#![allow(unused)]
+fn main() {
+type Opaque<'x> = impl Sized + 'x;
+
+fn test<'a>() -> Opaque<'a> {
+    // `Opaque<'empty> := ()`
+    let _: Opaque<'_> = ();
+    //~^ ERROR
+}
+}
+
+

Motivation: +This makes the lifetime and type arguments behave consistently but this is only as a bonus. +The real reason behind this restriction is purely technical, as the member constraints algorithm +faces a fundamental limitation: +When encountering an opaque type definition Opaque<'?1> := &'?2 u8, +a member constraint '?2 member-of ['static, '?1] is registered. +In order for the algorithm to pick the right choice, the complete set of "outlives" relationships +between the choice regions ['static, '?1] must already be known before doing the region +inference. This can be satisfied only if each choice region is either:

+
    +
  1. a universal region, i.e. RegionKind::Re{EarlyParam,LateParam,Placeholder,Static}, +because the relations between universal regions are completely known, prior to region inference, +from the explicit and implied bounds.
  2. +
  3. or an existential region that is "strictly equal" to a universal region. +Strict lifetime equality is defined below and is required here because it is the only type of +equality that can be evaluated prior to full region inference.
  4. +
+

Strict lifetime equality: +We say that two lifetimes are strictly equal if there are bidirectional outlives constraints +between them. In NLL terms, this means the lifetimes are part of the same SCC. +Importantly this type of equality can be evaluated prior to full region inference +(but of course after constraint collection). +The other type of equality is when region inference ends up giving two lifetimes variables +the same value even if they are not strictly equal. +See #113971 for how we used to conflate the difference.

+

interaction with "once modulo regions" restriction +In the example above, note the opaque type in the signature is Opaque<'a> and the one in the +invalid defining use is Opaque<'empty>. +In the proposed MiniTAIT plan, namely the "once modulo regions" rule, +we already disallow this. +Although it might appear that "universal lifetimes" restriction becomes redundant as it logically +follows from "MiniTAIT" restrictions, the subsequent related discussion on lifetime equality and +closures remains relevant.

+

Closure restrictions

+

When the opaque type is defined in a closure/coroutine/inline-const body, universal lifetimes that +are "external" to the closure are not allowed in the opaque type arguments. +External regions are defined in RegionClassification::External

+

Example: (This one happens to compile in the current nightly but more practical examples are +already rejected with confusing errors.)

+
#![allow(unused)]
+fn main() {
+type Opaque<'x> = impl Sized + 'x;
+
+fn test<'a>() -> Opaque<'a> {
+    let _ = || {
+        // `'a` is external to the closure
+        let _: Opaque<'a> = ();
+        //~^ Should be an error!
+    };
+    ()
+}
+}
+
+

Motivation: +In closure bodies, external lifetimes, although being categorized as "universal" lifetimes, +behave more like existential lifetimes in that the relations between them are not known ahead of +time, instead their values are inferred just like existential lifetimes and the requirements are +propagated back to the parent fn. This breaks the member constraints algorithm as described above:

+
+

In order for the algorithm to pick the right choice, the complete set of “outlives” relationships +between the choice regions ['static, '?1] must already be known before doing the region inference

+
+

Here is an example that details how :

+
#![allow(unused)]
+fn main() {
+type Opaque<'x, 'y> = impl Sized;
+
+// 
+fn test<'a, 'b>(s: &'a str) -> impl FnOnce() -> Opaque<'a, 'b> {
+    move || { s }
+    //~^ ERROR hidden type for `Opaque<'_, '_>` captures lifetime that does not appear in bounds
+}
+
+// The above closure body is desugared into something like:
+fn test::{closure#0}(_upvar: &'?8 str) -> Opaque<'?6, '?7> {
+    return _upvar
+}
+
+// where `['?8, '?6, ?7]` are universal lifetimes *external* to the closure.
+// There are no known relations between them *inside* the closure.
+// But in the parent fn it is known that `'?6: '?8`.
+//
+// When encountering an opaque definition `Opaque<'?6, '?7> := &'8 str`,
+// The member constraints algorithm does not know enough to safely make `?8 = '?6`.
+// For this reason, it errors with a sensible message:
+// "hidden type captures lifetime that does not appear in bounds".
+}
+
+

Without this restrictions error messages are consfusing and, more impotantly, there is a risk that +we accept code the we would likely break in the future because member constraints are super broken +in closures.

+

Output types: +I believe the most common scenario where this causes issues in real-world code is with +closure/async-block output types. It is worth noting that there is a discrepancy between closures +and async blocks that further demonstrates this issue and is attributed to the +hack of replace_opaque_types_with_inference_vars, +which is applied to futures only.

+
#![allow(unused)]
+fn main() {
+type Opaque<'x> = impl Sized + 'x;
+fn test<'a>() -> impl FnOnce() -> Opaque<'a> {
+    // Output type of the closure is Opaque<'a>
+    // -> hidden type definition happens *inside* the closure
+    // -> rejected.
+    move || {}
+    //~^ ERROR expected generic lifetime parameter, found `'_`
+}
+}
+
+
#![allow(unused)]
+fn main() {
+use std::future::Future;
+type Opaque<'x> = impl Sized + 'x;
+fn test<'a>() -> impl Future<Output = Opaque<'a>> {
+    // Output type of the async block is unit `()`
+    // -> hidden type definition happens in the parent fn
+    // -> accepted.
+    async move {}
+}
+}
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/region_inference.html b/borrow_check/region_inference.html new file mode 100644 index 000000000..e37357e23 --- /dev/null +++ b/borrow_check/region_inference.html @@ -0,0 +1,395 @@ + + + + + + Region inference - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Region inference (NLL)

+ +

The MIR-based region checking code is located in the rustc_mir::borrow_check +module.

+

The MIR-based region analysis consists of two major functions:

+
    +
  • replace_regions_in_mir, invoked first, has two jobs: +
      +
    • First, it finds the set of regions that appear within the +signature of the function (e.g., 'a in fn foo<'a>(&'a u32) { ... }). These are called the "universal" or "free" regions – in +particular, they are the regions that appear free in the +function body.
    • +
    • Second, it replaces all the regions from the function body with +fresh inference variables. This is because (presently) those +regions are the results of lexical region inference and hence are +not of much interest. The intention is that – eventually – they +will be "erased regions" (i.e., no information at all), since we +won't be doing lexical region inference at all.
    • +
    +
  • +
  • compute_regions, invoked second: this is given as argument the +results of move analysis. It has the job of computing values for all +the inference variables that replace_regions_in_mir introduced. +
      +
    • To do that, it first runs the MIR type checker. This is +basically a normal type-checker but specialized to MIR, which is +much simpler than full Rust, of course. Running the MIR type +checker will however create various constraints between region +variables, indicating their potential values and relationships to +one another.
    • +
    • After this, we perform constraint propagation by creating a +RegionInferenceContext and invoking its solve +method.
    • +
    • The NLL RFC also includes fairly thorough (and hopefully readable) +coverage.
    • +
    +
  • +
+

Universal regions

+

The UniversalRegions type represents a collection of universal regions +corresponding to some MIR DefId. It is constructed in +replace_regions_in_mir when we replace all regions with fresh inference +variables. UniversalRegions contains indices for all the free regions in +the given MIR along with any relationships that are known to hold between +them (e.g. implied bounds, where clauses, etc.).

+

For example, given the MIR for the following function:

+
#![allow(unused)]
+fn main() {
+fn foo<'a>(x: &'a u32) {
+    // ...
+}
+}
+
+

we would create a universal region for 'a and one for 'static. There may +also be some complications for handling closures, but we will ignore those for +the moment.

+

TODO: write about how these regions are computed.

+

+

Region variables

+

The value of a region can be thought of as a set. This set contains all +points in the MIR where the region is valid along with any regions that are +outlived by this region (e.g. if 'a: 'b, then end('b) is in the set for +'a); we call the domain of this set a RegionElement. In the code, the value +for all regions is maintained in the rustc_borrowck::region_infer module. +For each region we maintain a set storing what elements are present in its value (to make this +efficient, we give each kind of element an index, the RegionElementIndex, and +use sparse bitsets).

+

The kinds of region elements are as follows:

+
    +
  • Each location in the MIR control-flow graph: a location is just +the pair of a basic block and an index. This identifies the point +on entry to the statement with that index (or the terminator, if +the index is equal to statements.len()).
  • +
  • There is an element end('a) for each universal region 'a, +corresponding to some portion of the caller's (or caller's caller, +etc) control-flow graph.
  • +
  • Similarly, there is an element denoted end('static) corresponding +to the remainder of program execution after this function returns.
  • +
  • There is an element !1 for each placeholder region !1. This +corresponds (intuitively) to some unknown set of other elements – +for details on placeholders, see the section +placeholders and universes.
  • +
+

Constraints

+

Before we can infer the value of regions, we need to collect +constraints on the regions. The full set of constraints is described +in the section on constraint propagation, but the two most +common sorts of constraints are:

+
    +
  1. Outlives constraints. These are constraints that one region outlives another +(e.g. 'a: 'b). Outlives constraints are generated by the MIR type +checker.
  2. +
  3. Liveness constraints. Each region needs to be live at points where it can be +used.
  4. +
+

Inference Overview

+

So how do we compute the contents of a region? This process is called region +inference. The high-level idea is pretty simple, but there are some details we +need to take care of.

+

Here is the high-level idea: we start off each region with the MIR locations we +know must be in it from the liveness constraints. From there, we use all of the +outlives constraints computed from the type checker to propagate the +constraints: for each region 'a, if 'a: 'b, then we add all elements of +'b to 'a, including end('b). This all happens in +propagate_constraints.

+

Then, we will check for errors. We first check that type tests are satisfied by +calling check_type_tests. This checks constraints like T: 'a. Second, we +check that universal regions are not "too big". This is done by calling +check_universal_regions. This checks that for each region 'a if 'a +contains the element end('b), then we must already know that 'a: 'b holds +(e.g. from a where clause). If we don't already know this, that is an error... +well, almost. There is some special handling for closures that we will discuss +later.

+

Example

+

Consider the following example:

+
fn foo<'a, 'b>(x: &'a usize) -> &'b usize {
+    x
+}
+
+

Clearly, this should not compile because we don't know if 'a outlives 'b +(if it doesn't then the return value could be a dangling reference).

+

Let's back up a bit. We need to introduce some free inference variables (as is +done in replace_regions_in_mir). This example doesn't use the exact regions +produced, but it (hopefully) is enough to get the idea across.

+
fn foo<'a, 'b>(x: &'a /* '#1 */ usize) -> &'b /* '#3 */ usize {
+    x // '#2, location L1
+}
+
+

Some notation: '#1, '#3, and '#2 represent the universal regions for the +argument, return value, and the expression x, respectively. Additionally, I +will call the location of the expression x L1.

+

So now we can use the liveness constraints to get the following starting points:

+
+ + + +
RegionContents
'#1
'#2L1
'#3L1
+
+

Now we use the outlives constraints to expand each region. Specifically, we +know that '#2: '#3 ...

+
+ + + +
RegionContents
'#1L1
'#2L1, end('#3) // add contents of '#3 and end('#3)
'#3L1
+
+

... and '#1: '#2, so ...

+
+ + + +
RegionContents
'#1L1, end('#2), end('#3) // add contents of '#2 and end('#2)
'#2L1, end('#3)
'#3L1
+
+

Now, we need to check that no regions were too big (we don't have any type +tests to check in this case). Notice that '#1 now contains end('#3), but +we have no where clause or implied bound to say that 'a: 'b... that's an +error!

+

Some details

+

The RegionInferenceContext type contains all of the information needed to +do inference, including the universal regions from replace_regions_in_mir and +the constraints computed for each region. It is constructed just after we +compute the liveness constraints.

+

Here are some of the fields of the struct:

+
    +
  • constraints: contains all the outlives constraints.
  • +
  • liveness_constraints: contains all the liveness constraints.
  • +
  • universal_regions: contains the UniversalRegions returned by +replace_regions_in_mir.
  • +
  • universal_region_relations: contains relations known to be true about +universal regions. For example, if we have a where clause that 'a: 'b, that +relation is assumed to be true while borrow checking the implementation (it +is checked at the caller), so universal_region_relations would contain 'a: 'b.
  • +
  • type_tests: contains some constraints on types that we must check after +inference (e.g. T: 'a).
  • +
  • closure_bounds_mapping: used for propagating region constraints from +closures back out to the creator of the closure.
  • +
+

TODO: should we discuss any of the others fields? What about the SCCs?

+

Ok, now that we have constructed a RegionInferenceContext, we can do +inference. This is done by calling the solve method on the context. This +is where we call propagate_constraints and then check the resulting type +tests and universal regions, as discussed above.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/region_inference/closure_constraints.html b/borrow_check/region_inference/closure_constraints.html new file mode 100644 index 000000000..d4fd8e39f --- /dev/null +++ b/borrow_check/region_inference/closure_constraints.html @@ -0,0 +1,212 @@ + + + + + + Closure constraints - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Propagating closure constraints

+

When we are checking the type tests and universal regions, we may come +across a constraint that we can't prove yet if we are in a closure +body! However, the necessary constraints may actually hold (we just +don't know it yet). Thus, if we are inside a closure, we just collect +all the constraints we can't prove yet and return them. Later, when we +are borrow check the MIR node that created the closure, we can also +check that these constraints hold. At that time, if we can't prove +they hold, we report an error.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/region_inference/constraint_propagation.html b/borrow_check/region_inference/constraint_propagation.html new file mode 100644 index 000000000..1a5b67cbb --- /dev/null +++ b/borrow_check/region_inference/constraint_propagation.html @@ -0,0 +1,382 @@ + + + + + + Constraint propagation - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Constraint propagation

+ +

The main work of the region inference is constraint propagation, +which is done in the propagate_constraints function. There are +three sorts of constraints that are used in NLL, and we'll explain how +propagate_constraints works by "layering" those sorts of constraints +on one at a time (each of them is fairly independent from the others):

+
    +
  • liveness constraints (R live at E), which arise from liveness;
  • +
  • outlives constraints (R1: R2), which arise from subtyping;
  • +
  • member constraints (member R_m of [R_c...]), which arise from impl Trait.
  • +
+

In this chapter, we'll explain the "heart" of constraint propagation, +covering both liveness and outlives constraints.

+

Notation and high-level concepts

+

Conceptually, region inference is a "fixed-point" computation. It is +given some set of constraints {C} and it computes a set of values +Values: R -> {E} that maps each region R to a set of elements +{E} (see here for more notes on region elements):

+
    +
  • Initially, each region is mapped to an empty set, so Values(R) = {} for all regions R.
  • +
  • Next, we process the constraints repeatedly until a fixed-point is reached: +
      +
    • For each constraint C: +
        +
      • Update Values as needed to satisfy the constraint
      • +
      +
    • +
    +
  • +
+

As a simple example, if we have a liveness constraint R live at E, +then we can apply Values(R) = Values(R) union {E} to make the +constraint be satisfied. Similarly, if we have an outlives constraints +R1: R2, we can apply Values(R1) = Values(R1) union Values(R2). +(Member constraints are more complex and we discuss them in this section.)

+

In practice, however, we are a bit more clever. Instead of applying +the constraints in a loop, we can analyze the constraints and figure +out the correct order to apply them, so that we only have to apply +each constraint once in order to find the final result.

+

Similarly, in the implementation, the Values set is stored in the +scc_values field, but they are indexed not by a region but by a +strongly connected component (SCC). SCCs are an optimization that +avoids a lot of redundant storage and computation. They are explained +in the section on outlives constraints.

+

Liveness constraints

+

A liveness constraint arises when some variable whose type +includes a region R is live at some point P. This simply means that +the value of R must include the point P. Liveness constraints are +computed by the MIR type checker.

+

A liveness constraint R live at E is satisfied if E is a member of +Values(R). So to "apply" such a constraint to Values, we just have +to compute Values(R) = Values(R) union {E}.

+

The liveness values are computed in the type-check and passed to the +region inference upon creation in the liveness_constraints argument. +These are not represented as individual constraints like R live at E +though; instead, we store a (sparse) bitset per region variable (of +type LivenessValues). This way we only need a single bit for each +liveness constraint.

+

One thing that is worth mentioning: All lifetime parameters are always +considered to be live over the entire function body. This is because +they correspond to some portion of the caller's execution, and that +execution clearly includes the time spent in this function, since the +caller is waiting for us to return.

+

Outlives constraints

+

An outlives constraint 'a: 'b indicates that the value of 'a must +be a superset of the value of 'b. That is, an outlives +constraint R1: R2 is satisfied if Values(R1) is a superset of +Values(R2). So to "apply" such a constraint to Values, we just +have to compute Values(R1) = Values(R1) union Values(R2).

+

One observation that follows from this is that if you have R1: R2 +and R2: R1, then R1 = R2 must be true. Similarly, if you have:

+
R1: R2
+R2: R3
+R3: R4
+R4: R1
+
+

then R1 = R2 = R3 = R4 follows. We take advantage of this to make things +much faster, as described shortly.

+

In the code, the set of outlives constraints is given to the region +inference context on creation in a parameter of type +OutlivesConstraintSet. The constraint set is basically just a list of 'a: 'b constraints.

+

The outlives constraint graph and SCCs

+

In order to work more efficiently with outlives constraints, they are +converted into the form of a graph, where the nodes of the +graph are region variables ('a, 'b) and each constraint 'a: 'b +induces an edge 'a -> 'b. This conversion happens in the +RegionInferenceContext::new function that creates the inference +context.

+

When using a graph representation, we can detect regions that must be equal +by looking for cycles. That is, if you have a constraint like

+
'a: 'b
+'b: 'c
+'c: 'd
+'d: 'a
+
+

then this will correspond to a cycle in the graph containing the +elements 'a...'d.

+

Therefore, one of the first things that we do in propagating region +values is to compute the strongly connected components (SCCs) in +the constraint graph. The result is stored in the constraint_sccs +field. You can then easily find the SCC that a region r is a part of +by invoking constraint_sccs.scc(r).

+

Working in terms of SCCs allows us to be more efficient: if we have a +set of regions 'a...'d that are part of a single SCC, we don't have +to compute/store their values separately. We can just store one value +for the SCC, since they must all be equal.

+

If you look over the region inference code, you will see that a number +of fields are defined in terms of SCCs. For example, the +scc_values field stores the values of each SCC. To get the value +of a specific region 'a then, we first figure out the SCC that the +region is a part of, and then find the value of that SCC.

+

When we compute SCCs, we not only figure out which regions are a +member of each SCC, we also figure out the edges between them. So for example +consider this set of outlives constraints:

+
'a: 'b
+'b: 'a
+
+'a: 'c
+
+'c: 'd
+'d: 'c
+
+

Here we have two SCCs: S0 contains 'a and 'b, and S1 contains 'c +and 'd. But these SCCs are not independent: because 'a: 'c, that +means that S0: S1 as well. That is -- the value of S0 must be a +superset of the value of S1. One crucial thing is that this graph of +SCCs is always a DAG -- that is, it never has cycles. This is because +all the cycles have been removed to form the SCCs themselves.

+

Applying liveness constraints to SCCs

+

The liveness constraints that come in from the type-checker are +expressed in terms of regions -- that is, we have a map like +Liveness: R -> {E}. But we want our final result to be expressed +in terms of SCCs -- we can integrate these liveness constraints very +easily just by taking the union:

+
for each region R:
+  let S be the SCC that contains R
+  Values(S) = Values(S) union Liveness(R)
+
+

In the region inferencer, this step is done in RegionInferenceContext::new.

+

Applying outlives constraints

+

Once we have computed the DAG of SCCs, we use that to structure out +entire computation. If we have an edge S1 -> S2 between two SCCs, +that means that Values(S1) >= Values(S2) must hold. So, to compute +the value of S1, we first compute the values of each successor S2. +Then we simply union all of those values together. To use a +quasi-iterator-like notation:

+
Values(S1) =
+  s1.successors()
+    .map(|s2| Values(s2))
+    .union()
+
+

In the code, this work starts in the propagate_constraints +function, which iterates over all the SCCs. For each SCC S1, we +compute its value by first computing the value of its +successors. Since SCCs form a DAG, we don't have to be concerned about +cycles, though we do need to keep a set around to track whether we +have already processed a given SCC or not. For each successor S2, once +we have computed S2's value, we can union those elements into the +value for S1. (Although we have to be careful in this process to +properly handle higher-ranked +placeholders. Note that the value +for S1 already contains the liveness constraints, since they were +added in RegionInferenceContext::new.

+

Once that process is done, we now have the "minimal value" for S1, +taking into account all of the liveness and outlives +constraints. However, in order to complete the process, we must also +consider member constraints, which are described in a later +section.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/region_inference/error_reporting.html b/borrow_check/region_inference/error_reporting.html new file mode 100644 index 000000000..c134a57a4 --- /dev/null +++ b/borrow_check/region_inference/error_reporting.html @@ -0,0 +1,205 @@ + + + + + + Error reporting - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Reporting region errors

+

TODO: we should discuss how to generate errors from the results of these analyses.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/region_inference/lifetime_parameters.html b/borrow_check/region_inference/lifetime_parameters.html new file mode 100644 index 000000000..bcf9d85b4 --- /dev/null +++ b/borrow_check/region_inference/lifetime_parameters.html @@ -0,0 +1,299 @@ + + + + + + Lifetime parameters - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Universal regions

+ +

"Universal regions" is the name that the code uses to refer to "named +lifetimes" -- e.g., lifetime parameters and 'static. The name +derives from the fact that such lifetimes are "universally quantified" +(i.e., we must make sure the code is true for all values of those +lifetimes). It is worth spending a bit of discussing how lifetime +parameters are handled during region inference. Consider this example:

+
fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> &'b u32 {
+  x
+}
+
+

This example is intended not to compile, because we are returning x, +which has type &'a u32, but our signature promises that we will +return a &'b u32 value. But how are lifetimes like 'a and 'b +integrated into region inference, and how this error wind up being +detected?

+

Universal regions and their relationships to one another

+

Early on in region inference, one of the first things we do is to +construct a UniversalRegions struct. This struct tracks the +various universal regions in scope on a particular function. We also +create a UniversalRegionRelations struct, which tracks their +relationships to one another. So if you have e.g. where 'a: 'b, then +the UniversalRegionRelations struct would track that 'a: 'b is +known to hold (which could be tested with the outlives function.

+

Everything is a region variable

+

One important aspect of how NLL region inference works is that all +lifetimes are represented as numbered variables. This means that the +only variant of region_kind::RegionKind that we use is the ReVar +variant. These region variables are broken into two major categories, +based on their index:

+
    +
  • 0..N: universal regions -- the ones we are discussing here. In this +case, the code must be correct with respect to any value of those +variables that meets the declared relationships.
  • +
  • N..M: existential regions -- inference variables where the region +inferencer is tasked with finding some suitable value.
  • +
+

In fact, the universal regions can be further subdivided based on +where they were brought into scope (see the RegionClassification +type). These subdivisions are not important for the topics discussed +here, but become important when we consider closure constraint +propagation, so we discuss them there.

+

Universal lifetimes as the elements of a region's value

+

As noted previously, the value that we infer for each region is a set +{E}. The elements of this set can be points in the control-flow +graph, but they can also be an element end('a) corresponding to each +universal lifetime 'a. If the value for some region R0 includes +end('a), then this implies that R0 must extend until the end of 'a +in the caller.

+

The "value" of a universal region

+

During region inference, we compute a value for each universal region +in the same way as we compute values for other regions. This value +represents, effectively, the lower bound on that universal region +-- the things that it must outlive. We now describe how we use this +value to check for errors.

+

Liveness and universal regions

+

All universal regions have an initial liveness constraint that +includes the entire function body. This is because lifetime parameters +are defined in the caller and must include the entirety of the +function call that invokes this particular function. In addition, each +universal region 'a includes itself (that is, end('a)) in its +liveness constraint (i.e., 'a must extend until the end of +itself). In the code, these liveness constraints are setup in +init_free_and_bound_regions.

+

Propagating outlives constraints for universal regions

+

So, consider the first example of this section:

+
fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> &'b u32 {
+  x
+}
+
+

Here, returning x requires that &'a u32 <: &'b u32, which gives +rise to an outlives constraint 'a: 'b. Combined with our default liveness +constraints we get:

+
'a live at {B, end('a)} // B represents the "function body"
+'b live at {B, end('b)}
+'a: 'b
+
+

When we process the 'a: 'b constraint, therefore, we will add +end('b) into the value for 'a, resulting in a final value of {B, end('a), end('b)}.

+

Detecting errors

+

Once we have finished constraint propagation, we then enforce a +constraint that if some universal region 'a includes an element +end('b), then 'a: 'b must be declared in the function's bounds. If +not, as in our example, that is an error. This check is done in the +check_universal_regions function, which simply iterates over all +universal regions, inspects their final value, and tests against the +declared UniversalRegionRelations.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/region_inference/member_constraints.html b/borrow_check/region_inference/member_constraints.html new file mode 100644 index 000000000..9ff5f28a8 --- /dev/null +++ b/borrow_check/region_inference/member_constraints.html @@ -0,0 +1,353 @@ + + + + + + Member constraints - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Member constraints

+ +

A member constraint 'm member of ['c_1..'c_N] expresses that the +region 'm must be equal to some choice regions 'c_i (for +some i). These constraints cannot be expressed by users, but they +arise from impl Trait due to its lifetime capture rules. Consider a +function such as the following:

+
fn make(a: &'a u32, b: &'b u32) -> impl Trait<'a, 'b> { .. }
+
+

Here, the true return type (often called the "hidden type") is only +permitted to capture the lifetimes 'a or 'b. You can kind of see +this more clearly by desugaring that impl Trait return type into its +more explicit form:

+
type MakeReturn<'x, 'y> = impl Trait<'x, 'y>;
+fn make(a: &'a u32, b: &'b u32) -> MakeReturn<'a, 'b> { .. }
+
+

Here, the idea is that the hidden type must be some type that could +have been written in place of the impl Trait<'x, 'y> -- but clearly +such a type can only reference the regions 'x or 'y (or +'static!), as those are the only names in scope. This limitation is +then translated into a restriction to only access 'a or 'b because +we are returning MakeReturn<'a, 'b>, where 'x and 'y have been +replaced with 'a and 'b respectively.

+

Detailed example

+

To help us explain member constraints in more detail, let's spell out +the make example in a bit more detail. First off, let's assume that +you have some dummy trait:

+
trait Trait<'a, 'b> { }
+impl<T> Trait<'_, '_> for T { }
+
+

and this is the make function (in desugared form):

+
type MakeReturn<'x, 'y> = impl Trait<'x, 'y>;
+fn make(a: &'a u32, b: &'b u32) -> MakeReturn<'a, 'b> {
+  (a, b)
+}
+
+

What happens in this case is that the return type will be (&'0 u32, &'1 u32), +where '0 and '1 are fresh region variables. We will have the following +region constraints:

+
'0 live at {L}
+'1 live at {L}
+'a: '0
+'b: '1
+'0 member of ['a, 'b, 'static]
+'1 member of ['a, 'b, 'static]
+
+

Here the "liveness set" {L} corresponds to that subset of the body +where '0 and '1 are live -- basically the point from where the +return tuple is constructed to where it is returned (in fact, '0 and +'1 might have slightly different liveness sets, but that's not very +interesting to the point we are illustrating here).

+

The 'a: '0 and 'b: '1 constraints arise from subtyping. When we +construct the (a, b) value, it will be assigned type (&'0 u32, &'1 u32) -- the region variables reflect that the lifetimes of these +references could be made smaller. For this value to be created from +a and b, however, we do require that:

+
(&'a u32, &'b u32) <: (&'0 u32, &'1 u32)
+
+

which means in turn that &'a u32 <: &'0 u32 and hence that 'a: '0 +(and similarly that &'b u32 <: &'1 u32, 'b: '1).

+

Note that if we ignore member constraints, the value of '0 would be +inferred to some subset of the function body (from the liveness +constraints, which we did not write explicitly). It would never become +'a, because there is no need for it too -- we have a constraint that +'a: '0, but that just puts a "cap" on how large '0 can grow to +become. Since we compute the minimal value that we can, we are happy +to leave '0 as being just equal to the liveness set. This is where +member constraints come in.

+

Choices are always lifetime parameters

+

At present, the "choice" regions from a member constraint are always lifetime +parameters from the current function. As of October 2021, +this falls out from the placement of impl Trait, though in the future it may not +be the case. We take some advantage of this fact, as it simplifies the current +code. In particular, we don't have to consider a case like '0 member of ['1, 'static], in which the value of both '0 and '1 are being inferred and hence +changing. See rust-lang/rust#61773 for more information.

+

Applying member constraints

+

Member constraints are a bit more complex than other forms of +constraints. This is because they have a "or" quality to them -- that +is, they describe multiple choices that we must select from. E.g., in +our example constraint '0 member of ['a, 'b, 'static], it might be +that '0 is equal to 'a, 'b, or 'static. How can we pick the +correct one? What we currently do is to look for a minimal choice +-- if we find one, then we will grow '0 to be equal to that minimal +choice. To find that minimal choice, we take two factors into +consideration: lower and upper bounds.

+

Lower bounds

+

The lower bounds are those lifetimes that '0 must outlive -- +i.e., that '0 must be larger than. In fact, when it comes time to +apply member constraints, we've already computed the lower bounds of +'0 because we computed its minimal value (or at least, the lower +bounds considering everything but member constraints).

+

Let LB be the current value of '0. We know then that '0: LB must +hold, whatever the final value of '0 is. Therefore, we can rule out +any choice 'choice where 'choice: LB does not hold.

+

Unfortunately, in our example, this is not very helpful. The lower +bound for '0 will just be the liveness set {L}, and we know that +all the lifetime parameters outlive that set. So we are left with the +same set of choices here. (But in other examples, particularly those +with different variance, lower bound constraints may be relevant.)

+

Upper bounds

+

The upper bounds are those lifetimes that must outlive '0 -- +i.e., that '0 must be smaller than. In our example, this would be +'a, because we have the constraint that 'a: '0. In more complex +examples, the chain may be more indirect.

+

We can use upper bounds to rule out members in a very similar way to +lower bounds. If UB is some upper bound, then we know that UB: '0 must hold, so we can rule out any choice 'choice where UB: 'choice does not hold.

+

In our example, we would be able to reduce our choice set from ['a, 'b, 'static] to just ['a]. This is because '0 has an upper bound +of 'a, and neither 'a: 'b nor 'a: 'static is known to hold.

+

(For notes on how we collect upper bounds in the implementation, see +the section below.)

+

Minimal choice

+

After applying lower and upper bounds, we can still sometimes have +multiple possibilities. For example, imagine a variant of our example +using types with the opposite variance. In that case, we would have +the constraint '0: 'a instead of 'a: '0. Hence the current value +of '0 would be {L, 'a}. Using this as a lower bound, we would be +able to narrow down the member choices to ['a, 'static] because 'b: 'a is not known to hold (but 'a: 'a and 'static: 'a do hold). We +would not have any upper bounds, so that would be our final set of choices.

+

In that case, we apply the minimal choice rule -- basically, if +one of our choices if smaller than the others, we can use that. In +this case, we would opt for 'a (and not 'static).

+

This choice is consistent with the general 'flow' of region +propagation, which always aims to compute a minimal value for the +region being inferred. However, it is somewhat arbitrary.

+

+

Collecting upper bounds in the implementation

+

In practice, computing upper bounds is a bit inconvenient, because our +data structures are setup for the opposite. What we do is to compute +the reverse SCC graph (we do this lazily and cache the result) -- +that is, a graph where 'a: 'b induces an edge SCC('b) -> SCC('a). Like the normal SCC graph, this is a DAG. We can then do a +depth-first search starting from SCC('0) in this graph. This will +take us to all the SCCs that must outlive '0.

+

One wrinkle is that, as we walk the "upper bound" SCCs, their values +will not yet have been fully computed. However, we have already +applied their liveness constraints, so we have some information about +their value. In particular, for any regions representing lifetime +parameters, their value will contain themselves (i.e., the initial +value for 'a includes 'a and the value for 'b contains 'b). So +we can collect all of the lifetime parameters that are reachable, +which is precisely what we are interested in.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/region_inference/placeholders_and_universes.html b/borrow_check/region_inference/placeholders_and_universes.html new file mode 100644 index 000000000..1b8412549 --- /dev/null +++ b/borrow_check/region_inference/placeholders_and_universes.html @@ -0,0 +1,529 @@ + + + + + + Placeholders and universes - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Placeholders and universes

+ +

From time to time we have to reason about regions that we can't +concretely know. For example, consider this program:

+
// A function that needs a static reference
+fn foo(x: &'static u32) { }
+
+fn bar(f: for<'a> fn(&'a u32)) {
+       // ^^^^^^^^^^^^^^^^^^^ a function that can accept **any** reference
+    let x = 22;
+    f(&x);
+}
+
+fn main() {
+    bar(foo);
+}
+
+

This program ought not to type-check: foo needs a static reference +for its argument, and bar wants to be given a function that +accepts any reference (so it can call it with something on its +stack, for example). But how do we reject it and why?

+

Subtyping and Placeholders

+

When we type-check main, and in particular the call bar(foo), we +are going to wind up with a subtyping relationship like this one:

+
fn(&'static u32) <: for<'a> fn(&'a u32)
+----------------    -------------------
+the type of `foo`   the type `bar` expects
+
+

We handle this sort of subtyping by taking the variables that are +bound in the supertype and replacing them with +universally quantified +representatives, denoted like !1 here. We call these regions "placeholder +regions" – they represent, basically, "some unknown region".

+

Once we've done that replacement, we have the following relation:

+
fn(&'static u32) <: fn(&'!1 u32)
+
+

The key idea here is that this unknown region '!1 is not related to +any other regions. So if we can prove that the subtyping relationship +is true for '!1, then it ought to be true for any region, which is +what we wanted.

+

So let's work through what happens next. To check if two functions are +subtypes, we check if their arguments have the desired relationship +(fn arguments are contravariant, so +we swap the left and right here):

+
&'!1 u32 <: &'static u32
+
+

According to the basic subtyping rules for a reference, this will be +true if '!1: 'static. That is – if "some unknown region !1" outlives 'static. +Now, this might be true – after all, '!1 could be 'static – +but we don't know that it's true. So this should yield up an error (eventually).

+

What is a universe?

+

In the previous section, we introduced the idea of a placeholder +region, and we denoted it !1. We call this number 1 the universe +index. The idea of a "universe" is that it is a set of names that +are in scope within some type or at some point. Universes are formed +into a tree, where each child extends its parents with some new names. +So the root universe conceptually contains global names, such as +the lifetime 'static or the type i32. In the compiler, we also +put generic type parameters into this root universe (in this sense, +there is not just one root universe, but one per item). So consider +this function bar:

+
struct Foo { }
+
+fn bar<'a, T>(t: &'a T) {
+    ...
+}
+
+

Here, the root universe would consist of the lifetimes 'static and +'a. In fact, although we're focused on lifetimes here, we can apply +the same concept to types, in which case the types Foo and T would +be in the root universe (along with other global types, like i32). +Basically, the root universe contains all the names that +appear free in the body of bar.

+

Now let's extend bar a bit by adding a variable x:

+
fn bar<'a, T>(t: &'a T) {
+    let x: for<'b> fn(&'b u32) = ...;
+}
+
+

Here, the name 'b is not part of the root universe. Instead, when we +"enter" into this for<'b> (e.g., by replacing it with a placeholder), we will create +a child universe of the root, let's call it U1:

+
U0 (root universe)
+│
+└─ U1 (child universe)
+
+

The idea is that this child universe U1 extends the root universe U0 +with a new name, which we are identifying by its universe number: +!1.

+

Now let's extend bar a bit by adding one more variable, y:

+
fn bar<'a, T>(t: &'a T) {
+    let x: for<'b> fn(&'b u32) = ...;
+    let y: for<'c> fn(&'c u32) = ...;
+}
+
+

When we enter this type, we will again create a new universe, which +we'll call U2. Its parent will be the root universe, and U1 will be +its sibling:

+
U0 (root universe)
+│
+├─ U1 (child universe)
+│
+└─ U2 (child universe)
+
+

This implies that, while in U2, we can name things from U0 or U2, but +not U1.

+

Giving existential variables a universe. Now that we have this +notion of universes, we can use it to extend our type-checker and +things to prevent illegal names from leaking out. The idea is that we +give each inference (existential) variable – whether it be a type or +a lifetime – a universe. That variable's value can then only +reference names visible from that universe. So for example if a +lifetime variable is created in U0, then it cannot be assigned a value +of !1 or !2, because those names are not visible from the universe +U0.

+

Representing universes with just a counter. You might be surprised +to see that the compiler doesn't keep track of a full tree of +universes. Instead, it just keeps a counter – and, to determine if +one universe can see another one, it just checks if the index is +greater. For example, U2 can see U0 because 2 >= 0. But U0 cannot see +U2, because 0 >= 2 is false.

+

How can we get away with this? Doesn't this mean that we would allow +U2 to also see U1? The answer is that, yes, we would, if that +question ever arose. But because of the structure of our type +checker etc, there is no way for that to happen. In order for +something happening in the universe U1 to "communicate" with something +happening in U2, they would have to have a shared inference variable X +in common. And because everything in U1 is scoped to just U1 and its +children, that inference variable X would have to be in U0. And since +X is in U0, it cannot name anything from U1 (or U2). This is perhaps easiest +to see by using a kind of generic "logic" example:

+
exists<X> {
+   forall<Y> { ... /* Y is in U1 ... */ }
+   forall<Z> { ... /* Z is in U2 ... */ }
+}
+
+

Here, the only way for the two foralls to interact would be through X, +but neither Y nor Z are in scope when X is declared, so its value +cannot reference either of them.

+

Universes and placeholder region elements

+

But where does that error come from? The way it happens is like this. +When we are constructing the region inference context, we can tell +from the type inference context how many placeholder variables exist +(the InferCtxt has an internal counter). For each of those, we +create a corresponding universal region variable !n and a "region +element" placeholder(n). This corresponds to "some unknown set of other +elements". The value of !n is {placeholder(n)}.

+

At the same time, we also give each existential variable a +universe (also taken from the InferCtxt). This universe +determines which placeholder elements may appear in its value: For +example, a variable in universe U3 may name placeholder(1), placeholder(2), and +placeholder(3), but not placeholder(4). Note that the universe of an inference +variable controls what region elements can appear in its value; it +does not say region elements will appear.

+

Placeholders and outlives constraints

+

In the region inference engine, outlives constraints have the form:

+
V1: V2 @ P
+
+

where V1 and V2 are region indices, and hence map to some region +variable (which may be universally or existentially quantified). The +P here is a "point" in the control-flow graph; it's not important +for this section. This variable will have a universe, so let's call +those universes U(V1) and U(V2) respectively. (Actually, the only +one we are going to care about is U(V1).)

+

When we encounter this constraint, the ordinary procedure is to start +a DFS from P. We keep walking so long as the nodes we are walking +are present in value(V2) and we add those nodes to value(V1). If +we reach a return point, we add in any end(X) elements. That part +remains unchanged.

+

But then after that we want to iterate over the placeholder placeholder(x) +elements in V2 (each of those must be visible to U(V2), but we +should be able to just assume that is true, we don't have to check +it). We have to ensure that value(V1) outlives each of those +placeholder elements.

+

Now there are two ways that could happen. First, if U(V1) can see +the universe x (i.e., x <= U(V1)), then we can just add placeholder(x) +to value(V1) and be done. But if not, then we have to approximate: +we may not know what set of elements placeholder(x) represents, but we +should be able to compute some sort of upper bound B for it – +some region B that outlives placeholder(x). For now, we'll just use +'static for that (since it outlives everything) – in the future, we +can sometimes be smarter here (and in fact we have code for doing this +already in other contexts). Moreover, since 'static is in the root +universe U0, we know that all variables can see it – so basically if +we find that value(V2) contains placeholder(x) for some universe x +that V1 can't see, then we force V1 to 'static.

+

Extending the "universal regions" check

+

After all constraints have been propagated, the NLL region inference +has one final check, where it goes over the values that wound up being +computed for each universal region and checks that they did not get +'too large'. In our case, we will go through each placeholder region +and check that it contains only the placeholder(u) element it is known to +outlive. (Later, we might be able to know that there are relationships +between two placeholder regions and take those into account, as we do +for universal regions from the fn signature.)

+

Put another way, the "universal regions" check can be considered to be +checking constraints like:

+
{placeholder(1)}: V1
+
+

where {placeholder(1)} is like a constant set, and V1 is the variable we +made to represent the !1 region.

+

Back to our example

+

OK, so far so good. Now let's walk through what would happen with our +first example:

+
fn(&'static u32) <: fn(&'!1 u32) @ P  // this point P is not imp't here
+
+

The region inference engine will create a region element domain like this:

+
{ CFG; end('static); placeholder(1) }
+  ---  ------------  ------- from the universe `!1`
+  |    'static is always in scope
+  all points in the CFG; not especially relevant here
+
+

It will always create two universal variables, one representing +'static and one representing '!1. Let's call them Vs and V1. They +will have initial values like so:

+
Vs = { CFG; end('static) } // it is in U0, so can't name anything else
+V1 = { placeholder(1) }
+
+

From the subtyping constraint above, we would have an outlives constraint like

+
'!1: 'static @ P
+
+

To process this, we would grow the value of V1 to include all of Vs:

+
Vs = { CFG; end('static) }
+V1 = { CFG; end('static), placeholder(1) }
+
+

At that point, constraint propagation is complete, because all the +outlives relationships are satisfied. Then we would go to the "check +universal regions" portion of the code, which would test that no +universal region grew too large.

+

In this case, V1 did grow too large – it is not known to outlive +end('static), nor any of the CFG – so we would report an error.

+

Another example

+

What about this subtyping relationship?

+
for<'a> fn(&'a u32, &'a u32)
+    <:
+for<'b, 'c> fn(&'b u32, &'c u32)
+
+

Here we would replace the bound region in the supertype with a placeholder, as before, yielding:

+
for<'a> fn(&'a u32, &'a u32)
+    <:
+fn(&'!1 u32, &'!2 u32)
+
+

then we instantiate the variable on the left-hand side with an +existential in universe U2, yielding the following (?n is a notation +for an existential variable):

+
fn(&'?3 u32, &'?3 u32)
+    <:
+fn(&'!1 u32, &'!2 u32)
+
+

Then we break this down further:

+
&'!1 u32 <: &'?3 u32
+&'!2 u32 <: &'?3 u32
+
+

and even further, yield up our region constraints:

+
'!1: '?3
+'!2: '?3
+
+

Note that, in this case, both '!1 and '!2 have to outlive the +variable '?3, but the variable '?3 is not forced to outlive +anything else. Therefore, it simply starts and ends as the empty set +of elements, and hence the type-check succeeds here.

+

(This should surprise you a little. It surprised me when I first realized it. +We are saying that if we are a fn that needs both of its arguments to have +the same region, we can accept being called with arguments with two +distinct regions. That seems intuitively unsound. But in fact, it's fine, as +I tried to explain in this issue on the Rust issue +tracker long ago. The reason is that even if we get called with arguments of +two distinct lifetimes, those two lifetimes have some intersection (the call +itself), and that intersection can be our value of 'a that we use as the +common lifetime of our arguments. -nmatsakis)

+

Final example

+

Let's look at one last example. We'll extend the previous one to have +a return type:

+
for<'a> fn(&'a u32, &'a u32) -> &'a u32
+    <:
+for<'b, 'c> fn(&'b u32, &'c u32) -> &'b u32
+
+

Despite seeming very similar to the previous example, this case is going to get +an error. That's good: the problem is that we've gone from a fn that promises +to return one of its two arguments, to a fn that is promising to return the +first one. That is unsound. Let's see how it plays out.

+

First, we replace the bound region in the supertype with a placeholder:

+
for<'a> fn(&'a u32, &'a u32) -> &'a u32
+    <:
+fn(&'!1 u32, &'!2 u32) -> &'!1 u32
+
+

Then we instantiate the subtype with existentials (in U2):

+
fn(&'?3 u32, &'?3 u32) -> &'?3 u32
+    <:
+fn(&'!1 u32, &'!2 u32) -> &'!1 u32
+
+

And now we create the subtyping relationships:

+
&'!1 u32 <: &'?3 u32 // arg 1
+&'!2 u32 <: &'?3 u32 // arg 2
+&'?3 u32 <: &'!1 u32 // return type
+
+

And finally the outlives relationships. Here, let V1, V2, and V3 be the +variables we assign to !1, !2, and ?3 respectively:

+
V1: V3
+V2: V3
+V3: V1
+
+

Those variables will have these initial values:

+
V1 in U1 = {placeholder(1)}
+V2 in U2 = {placeholder(2)}
+V3 in U2 = {}
+
+

Now because of the V3: V1 constraint, we have to add placeholder(1) into V3 (and +indeed it is visible from V3), so we get:

+
V3 in U2 = {placeholder(1)}
+
+

then we have this constraint V2: V3, so we wind up having to enlarge +V2 to include placeholder(1) (which it can also see):

+
V2 in U2 = {placeholder(1), placeholder(2)}
+
+

Now constraint propagation is done, but when we check the outlives +relationships, we find that V2 includes this new element placeholder(1), +so we report an error.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/two_phase_borrows.html b/borrow_check/two_phase_borrows.html new file mode 100644 index 000000000..8d8cffac1 --- /dev/null +++ b/borrow_check/two_phase_borrows.html @@ -0,0 +1,286 @@ + + + + + + Two-phase-borrows - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Two-phase borrows

+

Two-phase borrows are a more permissive version of mutable borrows that allow +nested method calls such as vec.push(vec.len()). Such borrows first act as +shared borrows in a "reservation" phase and can later be "activated" into a +full mutable borrow.

+

Only certain implicit mutable borrows can be two-phase, any &mut or ref mut +in the source code is never a two-phase borrow. The cases where we generate a +two-phase borrow are:

+
    +
  1. The autoref borrow when calling a method with a mutable reference receiver.
  2. +
  3. A mutable reborrow in function arguments.
  4. +
  5. The implicit mutable borrow in an overloaded compound assignment operator.
  6. +
+

To give some examples:

+
#![allow(unused)]
+fn main() {
+// In the source code
+
+// Case 1:
+let mut v = Vec::new();
+v.push(v.len());
+let r = &mut Vec::new();
+r.push(r.len());
+
+// Case 2:
+std::mem::replace(r, vec![1, r.len()]);
+
+// Case 3:
+let mut x = std::num::Wrapping(2);
+x += x;
+}
+
+

Expanding these enough to show the two-phase borrows:

+
// Case 1:
+let mut v = Vec::new();
+let temp1 = &two_phase v;
+let temp2 = v.len();
+Vec::push(temp1, temp2);
+let r = &mut Vec::new();
+let temp3 = &two_phase *r;
+let temp4 = r.len();
+Vec::push(temp3, temp4);
+
+// Case 2:
+let temp5 = &two_phase *r;
+let temp6 = vec![1, r.len()];
+std::mem::replace(temp5, temp6);
+
+// Case 3:
+let mut x = std::num::Wrapping(2);
+let temp7 = &two_phase x;
+let temp8 = x;
+std::ops::AddAssign::add_assign(temp7, temp8);
+
+

Whether a borrow can be two-phase is tracked by a flag on the AutoBorrow +after type checking, which is then converted to a BorrowKind during MIR +construction.

+

Each two-phase borrow is assigned to a temporary that is only used once. As +such we can define:

+
    +
  • The point where the temporary is assigned to is called the reservation +point of the two-phase borrow.
  • +
  • The point where the temporary is used, which is effectively always a +function call, is called the activation point.
  • +
+

The activation points are found using the GatherBorrows visitor. The +BorrowData then holds both the reservation and activation points for the +borrow.

+

Checking two-phase borrows

+

Two-phase borrows are treated as if they were mutable borrows with the +following exceptions:

+
    +
  1. At every location in the MIR we check if any two-phase borrows are +activated at this location. If a live two phase borrow is activated at a +location, then we check that there are no borrows that conflict with the +two-phase borrow.
  2. +
  3. At the reservation point we error if there are conflicting live mutable +borrows. And lint if there are any conflicting shared borrows.
  4. +
  5. Between the reservation and the activation point, the two-phase borrow acts +as a shared borrow. We determine (in is_active) if we're at such a point +by using the Dominators for the MIR graph.
  6. +
  7. After the activation point, the two-phase borrow acts as a mutable borrow.
  8. +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/borrow_check/type_check.html b/borrow_check/type_check.html new file mode 100644 index 000000000..e09e682fc --- /dev/null +++ b/borrow_check/type_check.html @@ -0,0 +1,252 @@ + + + + + + MIR type checker - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

The MIR type-check

+

A key component of the borrow check is the +MIR type-check. +This check walks the MIR and does a complete "type check" -- the same +kind you might find in any other language. In the process of doing +this type-check, we also uncover the region constraints that apply to +the program.

+

TODO -- elaborate further? Maybe? :)

+

User types

+

At the start of MIR type-check, we replace all regions in the body with new unconstrained regions. +However, this would cause us to accept the following program:

+
#![allow(unused)]
+fn main() {
+fn foo<'a>(x: &'a u32) {
+    let y: &'static u32 = x;
+}
+}
+
+

By erasing the lifetimes in the type of y we no longer know that it is supposed to be 'static, +ignoring the intentions of the user.

+

To deal with this we remember all places where the user explicitly mentioned a type during +HIR type-check as CanonicalUserTypeAnnotations.

+

There are two different annotations we care about:

+
    +
  • explicit type ascriptions, e.g. let y: &'static u32 results in UserType::Ty(&'static u32).
  • +
  • explicit generic arguments, e.g. x.foo<&'a u32, Vec<String>> +results in UserType::TypeOf(foo_def_id, [&'a u32, Vec<String>]).
  • +
+

As we do not want the region inference from the HIR type-check to influence MIR typeck, +we store the user type right after lowering it from the HIR. +This means that it may still contain inference variables, +which is why we are using canonical user type annotations. +We replace all inference variables with existential bound variables instead. +Something like let x: Vec<_> would therefore result in exists<T> UserType::Ty(Vec<T>).

+

A pattern like let Foo(x): Foo<&'a u32> has a user type Foo<&'a u32> but +the actual type of x should only be &'a u32. For this, we use a UserTypeProjection.

+

In the MIR, we deal with user types in two slightly different ways.

+

Given a MIR local corresponding to a variable in a pattern which has an explicit type annotation, +we require the type of that local to be equal to the type of the UserTypeProjection. +This is directly stored in the LocalDecl.

+

We also constrain the type of scrutinee expressions, e.g. the type of x in let _: &'a u32 = x;. +Here T_x only has to be a subtype of the user type, so we instead use +StatementKind::AscribeUserType for that.

+

Note that we do not directly use the user type as the MIR typechecker +doesn't really deal with type and const inference variables. We instead store the final +inferred_type from the HIR type-checker. During MIR typeck, we then replace its regions +with new nll inference vars and relate it with the actual UserType to get the correct region +constraints again.

+

After the MIR type-check, all user type annotations get discarded, as they aren't needed anymore.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/bug-fix-procedure.html b/bug-fix-procedure.html new file mode 100644 index 000000000..4e3ecfce1 --- /dev/null +++ b/bug-fix-procedure.html @@ -0,0 +1,525 @@ + + + + + + Procedures for Breaking Changes - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Procedures for Breaking Changes

+ +

This page defines the best practices procedure for making bug fixes or soundness +corrections in the compiler that can cause existing code to stop compiling. This +text is based on +RFC 1589.

+

Motivation

+

From time to time, we encounter the need to make a bug fix, soundness +correction, or other change in the compiler which will cause existing code to +stop compiling. When this happens, it is important that we handle the change in +a way that gives users of Rust a smooth transition. What we want to avoid is +that existing programs suddenly stop compiling with opaque error messages: we +would prefer to have a gradual period of warnings, with clear guidance as to +what the problem is, how to fix it, and why the change was made. This RFC +describes the procedure that we have been developing for handling breaking +changes that aims to achieve that kind of smooth transition.

+

One of the key points of this policy is that (a) warnings should be issued +initially rather than hard errors if at all possible and (b) every change that +causes existing code to stop compiling will have an associated tracking issue. +This issue provides a point to collect feedback on the results of that change. +Sometimes changes have unexpectedly large consequences or there may be a way to +avoid the change that was not considered. In those cases, we may decide to +change course and roll back the change, or find another solution (if warnings +are being used, this is particularly easy to do).

+

What qualifies as a bug fix?

+

Note that this RFC does not try to define when a breaking change is permitted. +That is already covered under RFC 1122. This document assumes that the +change being made is in accordance with those policies. Here is a summary of the +conditions from RFC 1122:

+
    +
  • Soundness changes: Fixes to holes uncovered in the type system.
  • +
  • Compiler bugs: Places where the compiler is not implementing the specified +semantics found in an RFC or lang-team decision.
  • +
  • Underspecified language semantics: Clarifications to grey areas where the +compiler behaves inconsistently and no formal behavior had been previously +decided.
  • +
+

Please see the RFC for full details!

+

Detailed design

+

The procedure for making a breaking change is as follows (each of these steps is +described in more detail below):

+
    +
  1. Do a crater run to assess the impact of the change.
  2. +
  3. Make a special tracking issue dedicated to the change.
  4. +
  5. Do not report an error right away. Instead, issue forwards-compatibility +lint warnings. +
      +
    • Sometimes this is not straightforward. See the text below for suggestions +on different techniques we have employed in the past.
    • +
    • For cases where warnings are infeasible: +
        +
      • Report errors, but make every effort to give a targeted error message +that directs users to the tracking issue
      • +
      • Submit PRs to all known affected crates that fix the issue +
          +
        • or, at minimum, alert the owners of those crates to the problem and +direct them to the tracking issue
        • +
        +
      • +
      +
    • +
    +
  6. +
  7. Once the change has been in the wild for at least one cycle, we can +stabilize the change, converting those warnings into errors.
  8. +
+

Finally, for changes to rustc_ast that will affect plugins, the general policy +is to batch these changes. That is discussed below in more detail.

+

Tracking issue

+

Every breaking change should be accompanied by a dedicated tracking issue +for that change. The main text of this issue should describe the change being +made, with a focus on what users must do to fix their code. The issue should be +approachable and practical; it may make sense to direct users to an RFC or some +other issue for the full details. The issue also serves as a place where users +can comment with questions or other concerns.

+

A template for these breaking-change tracking issues can be found below. An +example of how such an issue should look can be found +here.

+

The issue should be tagged with (at least) B-unstable and T-compiler.

+

Tracking issue template

+

This is a template to use for tracking issues:

+
This is the **summary issue** for the `YOUR_LINT_NAME_HERE`
+future-compatibility warning and other related errors. The goal of
+this page is describe why this change was made and how you can fix
+code that is affected by it. It also provides a place to ask questions
+or register a complaint if you feel the change should not be made. For
+more information on the policy around future-compatibility warnings,
+see our [breaking change policy guidelines][guidelines].
+
+[guidelines]: LINK_TO_THIS_RFC
+
+#### What is the warning for?
+
+*Describe the conditions that trigger the warning and how they can be
+fixed. Also explain why the change was made.**
+
+#### When will this warning become a hard error?
+
+At the beginning of each 6-week release cycle, the Rust compiler team
+will review the set of outstanding future compatibility warnings and
+nominate some of them for **Final Comment Period**. Toward the end of
+the cycle, we will review any comments and make a final determination
+whether to convert the warning into a hard error or remove it
+entirely.
+
+

Issuing future compatibility warnings

+

The best way to handle a breaking change is to begin by issuing +future-compatibility warnings. These are a special category of lint warning. +Adding a new future-compatibility warning can be done as follows.

+
#![allow(unused)]
+fn main() {
+// 1. Define the lint in `compiler/rustc_middle/src/lint/builtin.rs`:
+declare_lint! {
+    pub YOUR_ERROR_HERE,
+    Warn,
+    "illegal use of foo bar baz"
+}
+
+// 2. Add to the list of HardwiredLints in the same file:
+impl LintPass for HardwiredLints {
+    fn get_lints(&self) -> LintArray {
+        lint_array!(
+            ..,
+            YOUR_ERROR_HERE
+        )
+    }
+}
+
+// 3. Register the lint in `compiler/rustc_lint/src/lib.rs`:
+store.register_future_incompatible(sess, vec![
+    ...,
+    FutureIncompatibleInfo {
+        id: LintId::of(YOUR_ERROR_HERE),
+        reference: "issue #1234", // your tracking issue here!
+    },
+]);
+
+// 4. Report the lint:
+tcx.lint_node(
+    lint::builtin::YOUR_ERROR_HERE,
+    path_id,
+    binding.span,
+    format!("some helper message here"));
+}
+
+

Helpful techniques

+

It can often be challenging to filter out new warnings from older, pre-existing +errors. One technique that has been used in the past is to run the older code +unchanged and collect the errors it would have reported. You can then issue +warnings for any errors you would give which do not appear in that original set. +Another option is to abort compilation after the original code completes if +errors are reported: then you know that your new code will only execute when +there were no errors before.

+

Crater and crates.io

+

Crater is a bot that will compile all crates.io crates and many +public github repos with the compiler with your changes. A report will then be +generated with crates that ceased to compile with or began to compile with your +changes. Crater runs can take a few days to complete.

+

We should always do a crater run to assess impact. It is polite and considerate +to at least notify the authors of affected crates the breaking change. If we can +submit PRs to fix the problem, so much the better.

+

Is it ever acceptable to go directly to issuing errors?

+

Changes that are believed to have negligible impact can go directly to issuing +an error. One rule of thumb would be to check against crates.io: if fewer than +10 total affected projects are found (not root errors), we can move +straight to an error. In such cases, we should still make the "breaking change" +page as before, and we should ensure that the error directs users to this page. +In other words, everything should be the same except that users are getting an +error, and not a warning. Moreover, we should submit PRs to the affected +projects (ideally before the PR implementing the change lands in rustc).

+

If the impact is not believed to be negligible (e.g., more than 10 crates are +affected), then warnings are required (unless the compiler team agrees to grant +a special exemption in some particular case). If implementing warnings is not +feasible, then we should make an aggressive strategy of migrating crates before +we land the change so as to lower the number of affected crates. Here are some +techniques for approaching this scenario:

+
    +
  1. Issue warnings for subparts of the problem, and reserve the new errors for +the smallest set of cases you can.
  2. +
  3. Try to give a very precise error message that suggests how to fix the problem +and directs users to the tracking issue.
  4. +
  5. It may also make sense to layer the fix: +
      +
    • First, add warnings where possible and let those land before proceeding to +issue errors.
    • +
    • Work with authors of affected crates to ensure that corrected versions are +available before the fix lands, so that downstream users can use them.
    • +
    +
  6. +
+

Stabilization

+

After a change is made, we will stabilize the change using the same process +that we use for unstable features:

+
    +
  • +

    After a new release is made, we will go through the outstanding tracking +issues corresponding to breaking changes and nominate some of them for final +comment period (FCP).

    +
  • +
  • +

    The FCP for such issues lasts for one cycle. In the final week or two of the +cycle, we will review comments and make a final determination:

    +
      +
    • Convert to error: the change should be made into a hard error.
    • +
    • Revert: we should remove the warning and continue to allow the older code to +compile.
    • +
    • Defer: can't decide yet, wait longer, or try other strategies.
    • +
    +
  • +
+

Ideally, breaking changes should have landed on the stable branch of the +compiler before they are finalized.

+ +

Removing a lint

+

Once we have decided to make a "future warning" into a hard error, we need a PR +that removes the custom lint. As an example, here are the steps required to +remove the overlapping_inherent_impls compatibility lint. First, convert the +name of the lint to uppercase (OVERLAPPING_INHERENT_IMPLS) ripgrep through the +source for that string. We will basically by converting each place where this +lint name is mentioned (in the compiler, we use the upper-case name, and a macro +automatically generates the lower-case string; so searching for +overlapping_inherent_impls would not find much).

+
+

NOTE: these exact files don't exist anymore, but the procedure is still the same.

+
+

Remove the lint.

+

The first reference you will likely find is the lint definition in +rustc_session/src/lint/builtin.rs that resembles this:

+
#![allow(unused)]
+fn main() {
+declare_lint! {
+    pub OVERLAPPING_INHERENT_IMPLS,
+    Deny, // this may also say Warning
+    "two overlapping inherent impls define an item with the same name were erroneously allowed"
+}
+}
+
+

This declare_lint! macro creates the relevant data structures. Remove it. You +will also find that there is a mention of OVERLAPPING_INHERENT_IMPLS later in +the file as part of a lint_array!; remove it too.

+

Next, you see a reference to OVERLAPPING_INHERENT_IMPLS in +rustc_lint/src/lib.rs. This is defining the lint as a "future +compatibility lint":

+
#![allow(unused)]
+fn main() {
+FutureIncompatibleInfo {
+    id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
+    reference: "issue #36889 <https://github.com/rust-lang/rust/issues/36889>",
+},
+}
+
+

Remove this too.

+

Add the lint to the list of removed lints.

+

In compiler/rustc_lint/src/lib.rs there is a list of "renamed and removed lints". +You can add this lint to the list:

+
#![allow(unused)]
+fn main() {
+store.register_removed("overlapping_inherent_impls", "converted into hard error, see #36889");
+}
+
+

where #36889 is the tracking issue for your lint.

+

Update the places that issue the lint

+

Finally, the last class of references you will see are the places that actually +trigger the lint itself (i.e., what causes the warnings to appear). These +you do not want to delete. Instead, you want to convert them into errors. In +this case, the add_lint call looks like this:

+
#![allow(unused)]
+fn main() {
+self.tcx.sess.add_lint(lint::builtin::OVERLAPPING_INHERENT_IMPLS,
+                       node_id,
+                       self.tcx.span_of_impl(item1).unwrap(),
+                       msg);
+}
+
+

We want to convert this into an error. In some cases, there may be an +existing error for this scenario. In others, we will need to allocate a +fresh diagnostic code. Instructions for allocating a fresh diagnostic +code can be found here. You may want +to mention in the extended description that the compiler behavior +changed on this point, and include a reference to the tracking issue for +the change.

+

Let's say that we've adopted E0592 as our code. Then we can change the +add_lint() call above to something like:

+
#![allow(unused)]
+fn main() {
+struct_span_code_err!(self.dcx(), self.tcx.span_of_impl(item1).unwrap(), E0592, msg)
+    .emit();
+}
+
+

Update tests

+

Finally, run the test suite. These should be some tests that used to reference +the overlapping_inherent_impls lint, those will need to be updated. In +general, if the test used to have #[deny(overlapping_inherent_impls)], that +can just be removed.

+
./x test
+
+

All done!

+

Open a PR. =)

+ + +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/bootstrapping/how-bootstrap-does-it.html b/building/bootstrapping/how-bootstrap-does-it.html new file mode 100644 index 000000000..f19ebde92 --- /dev/null +++ b/building/bootstrapping/how-bootstrap-does-it.html @@ -0,0 +1,245 @@ + + + + + + How Bootstrap does it - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

How Bootstrap does it

+

The core concept in Bootstrap is a build Step, which are chained together +by Builder::ensure. Builder::ensure takes a Step as input, and runs +the Step if and only if it has not already been run. Let's take a closer +look at Step.

+

Synopsis of Step

+

A Step represents a granular collection of actions involved in the process +of producing some artifact. It can be thought of like a rule in Makefiles. +The Step trait is defined as:

+
pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
+    type Output: Clone;
+
+    const DEFAULT: bool = false;
+    const ONLY_HOSTS: bool = false;
+
+    // Required methods
+    fn run(self, builder: &Builder<'_>) -> Self::Output;
+    fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_>;
+
+    // Provided method
+    fn make_run(_run: RunConfig<'_>) { ... }
+}
+
+
    +
  • run is the function that is responsible for doing the work. +Builder::ensure invokes run.
  • +
  • should_run is the command-line interface, which determines if an invocation +such as x build foo should run a given Step. In a "default" context +where no paths are provided, then make_run is called directly.
  • +
  • make_run is invoked only for things directly asked via the CLI and not +for steps which are dependencies of other steps.
  • +
+

The entry points

+

There's a couple of preliminary steps before core Bootstrap code is reached:

+
    +
  1. Shell script or make: ./x or ./x.ps1 or make
  2. +
  3. Convenience wrapper script: x.py
  4. +
  5. src/bootstrap/bootstrap.py
  6. +
  7. src/bootstrap/src/bin/main.rs
  8. +
+

See src/bootstrap/README.md +for a more specific description of the implementation details.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/bootstrapping/intro.html b/building/bootstrapping/intro.html new file mode 100644 index 000000000..485141557 --- /dev/null +++ b/building/bootstrapping/intro.html @@ -0,0 +1,217 @@ + + + + + + Prologue - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Bootstrapping the compiler

+

Bootstrapping is the process of using a compiler to compile itself. +More accurately, it means using an older compiler to compile a newer version +of the same compiler.

+

This raises a chicken-and-egg paradox: where did the first compiler come from? +It must have been written in a different language. In Rust's case it was +written in OCaml. However it was abandoned long ago and the +only way to build a modern version of rustc is a slightly less modern +version.

+

This is exactly how x.py works: it downloads the current beta release of +rustc, then uses it to compile the new compiler.

+

In this section, we give a high-level overview of +what Bootstrap does, followed by a high-level +introduction to how Bootstrap does it.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/bootstrapping/what-bootstrapping-does.html b/building/bootstrapping/what-bootstrapping-does.html new file mode 100644 index 000000000..fc8d4cdf8 --- /dev/null +++ b/building/bootstrapping/what-bootstrapping-does.html @@ -0,0 +1,605 @@ + + + + + + What Bootstrapping does - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

What Bootstrapping does

+ +

Bootstrapping is the process of using a compiler to compile itself. +More accurately, it means using an older compiler to compile a newer version of +the same compiler.

+

This raises a chicken-and-egg paradox: where did the first compiler come from? +It must have been written in a different language. In Rust's case it was +written in OCaml. However it was abandoned long ago and the +only way to build a modern version of rustc is a slightly less modern version.

+

This is exactly how ./x.py works: it downloads the current beta release of +rustc, then uses it to compile the new compiler.

+

Note that this documentation mostly covers user-facing information. See +bootstrap/README.md to read about bootstrap internals.

+

Stages of bootstrapping

+

Overview

+
    +
  • Stage 0: the pre-compiled compiler
  • +
  • Stage 1: from current code, by an earlier compiler
  • +
  • Stage 2: the truly current compiler
  • +
  • Stage 3: the same-result test
  • +
+

Compiling rustc is done in stages. Here's a diagram, adapted from Jynn +Nelson's talk on bootstrapping at RustConf 2022, with +detailed explanations below.

+

The A, B, C, and D show the ordering of the stages of bootstrapping. +Blue nodes are +downloaded, yellow +nodes are built with the stage0 compiler, and green nodes are built with the stage1 +compiler.

+
graph TD
+    s0c["stage0 compiler (1.63)"]:::downloaded -->|A| s0l("stage0 std (1.64)"):::with-s0c;
+    s0c & s0l --- stepb[ ]:::empty;
+    stepb -->|B| s0ca["stage0 compiler artifacts (1.64)"]:::with-s0c;
+    s0ca -->|copy| s1c["stage1 compiler (1.64)"]:::with-s0c;
+    s1c -->|C| s1l("stage1 std (1.64)"):::with-s1c;
+    s1c & s1l --- stepd[ ]:::empty;
+    stepd -->|D| s1ca["stage1 compiler artifacts (1.64)"]:::with-s1c;
+    s1ca -->|copy| s2c["stage2 compiler"]:::with-s1c;
+
+    classDef empty width:0px,height:0px;
+    classDef downloaded fill: lightblue;
+    classDef with-s0c fill: yellow;
+    classDef with-s1c fill: lightgreen;
+
+

Stage 0: the pre-compiled compiler

+

The stage0 compiler is usually the current beta rustc compiler and its +associated dynamic libraries, which ./x.py will download for you. (You can +also configure ./x.py to use something else.)

+

The stage0 compiler is then used only to compile src/bootstrap, +library/std, and compiler/rustc. When assembling the libraries and +binaries that will become the stage1 rustc compiler, the freshly compiled +std and rustc are used. There are two concepts at play here: a compiler +(with its set of dependencies) and its 'target' or 'object' libraries (std and +rustc). Both are staged, but in a staggered manner.

+

Stage 1: from current code, by an earlier compiler

+

The rustc source code is then compiled with the stage0 compiler to produce the +stage1 compiler.

+

Stage 2: the truly current compiler

+

We then rebuild our stage1 compiler with itself to produce the stage2 +compiler.

+

In theory, the stage1 compiler is functionally identical to the stage2 +compiler, but in practice there are subtle differences. In particular, the +stage1 compiler itself was built by stage0 and hence not by the source in +your working directory. This means that the ABI generated by the stage0 +compiler may not match the ABI that would have been made by the stage1 +compiler, which can cause problems for dynamic libraries, tests, and tools using +rustc_private.

+

Note that the proc_macro crate avoids this issue with a C FFI layer called +proc_macro::bridge, allowing it to be used with stage1.

+

The stage2 compiler is the one distributed with rustup and all other install +methods. However, it takes a very long time to build because one must first +build the new compiler with an older compiler and then use that to build the new +compiler with itself. For development, you usually only want the stage1 +compiler, which you can build with ./x build library. See Building the +compiler.

+

Stage 3: the same-result test

+

Stage 3 is optional. To sanity check our new compiler we can build the libraries +with the stage2 compiler. The result ought to be identical to before, unless +something has broken.

+

Building the stages

+

The script ./x tries to be helpful and pick the stage you most likely meant +for each subcommand. These defaults are as follows:

+
    +
  • check: --stage 0
  • +
  • doc: --stage 0
  • +
  • build: --stage 1
  • +
  • test: --stage 1
  • +
  • dist: --stage 2
  • +
  • install: --stage 2
  • +
  • bench: --stage 2
  • +
+

You can always override the stage by passing --stage N explicitly.

+

For more information about stages, see +below.

+

Complications of bootstrapping

+

Since the build system uses the current beta compiler to build a stage1 +bootstrapping compiler, the compiler source code can't use some features until +they reach beta (because otherwise the beta compiler doesn't support them). On +the other hand, for compiler intrinsics and internal features, the +features have to be used. Additionally, the compiler makes heavy use of +nightly features (#![feature(...)]). How can we resolve this problem?

+

There are two methods used:

+
    +
  1. The build system sets --cfg bootstrap when building with stage0, so we +can use cfg(not(bootstrap)) to only use features when built with stage1. +Setting --cfg bootstrap in this way is used for features that were just +stabilized, which require #![feature(...)] when built with stage0, but +not for stage1.
  2. +
  3. The build system sets RUSTC_BOOTSTRAP=1. This special variable means to +break the stability guarantees of Rust: allowing use of #![feature(...)] +with a compiler that's not nightly. Setting RUSTC_BOOTSTRAP=1 should +never be used except when bootstrapping the compiler.
  4. +
+

Understanding stages of bootstrap

+

Overview

+

This is a detailed look into the separate bootstrap stages.

+

The convention ./x uses is that:

+
    +
  • A --stage N flag means to run the stage N compiler (stageN/rustc).
  • +
  • A "stage N artifact" is a build artifact that is produced by the stage N +compiler.
  • +
  • The stage N+1 compiler is assembled from stage N artifacts. This process is +called uplifting.
  • +
+

Build artifacts

+

Anything you can build with ./x is a build artifact. Build artifacts +include, but are not limited to:

+
    +
  • binaries, like stage0-rustc/rustc-main
  • +
  • shared objects, like stage0-sysroot/rustlib/libstd-6fae108520cf72fe.so
  • +
  • rlib files, like stage0-sysroot/rustlib/libstd-6fae108520cf72fe.rlib
  • +
  • HTML files generated by rustdoc, like doc/std
  • +
+

Examples

+
    +
  • ./x test tests/ui means to build the stage1 compiler and run compiletest +on it. If you're working on the compiler, this is normally the test command +you want.
  • +
  • ./x test --stage 0 library/std means to run tests on the standard library +without building rustc from source ('build with stage0, then test the +artifacts'). If you're working on the standard library, this is normally the +test command you want.
  • +
  • ./x build --stage 0 means to build with the beta rustc.
  • +
  • ./x doc --stage 0 means to document using the beta rustdoc.
  • +
+

Examples of what not to do

+
    +
  • ./x test --stage 0 tests/ui is not useful: it runs tests on the beta +compiler and doesn't build rustc from source. Use test tests/ui instead, +which builds stage1 from source.
  • +
  • ./x test --stage 0 compiler/rustc builds the compiler but runs no tests: +it's running cargo test -p rustc, but cargo doesn't understand Rust's +tests. You shouldn't need to use this, use test instead (without arguments).
  • +
  • ./x build --stage 0 compiler/rustc builds the compiler, but does not build +libstd or even libcore. Most of the time, you'll want ./x build library +instead, which allows compiling programs without needing to define lang items.
  • +
+

Building vs. running

+

Note that build --stage N compiler/rustc does not build the stage N +compiler: instead it builds the stage N+1 compiler using the stage N compiler.

+

In short, stage 0 uses the stage0 compiler to create stage0 artifacts which +will later be uplifted to be the stage1 compiler.

+

In each stage, two major steps are performed:

+
    +
  1. std is compiled by the stage N compiler.
  2. +
  3. That std is linked to programs built by the stage N compiler, including the +stage N artifacts (stage N+1 compiler).
  4. +
+

This is somewhat intuitive if one thinks of the stage N artifacts as "just" +another program we are building with the stage N compiler: build --stage N compiler/rustc is linking the stage N artifacts to the std built by the stage +N compiler.

+

Stages and std

+

Note that there are two std libraries in play here:

+
    +
  1. The library linked to stageN/rustc, which was built by stage N-1 (stage +N-1 std)
  2. +
  3. The library used to compile programs with stageN/rustc, which was built +by stage N (stage N std).
  4. +
+

Stage N std is pretty much necessary for any useful work with the stage N +compiler. Without it, you can only compile programs with #![no_core] -- not +terribly useful!

+

The reason these need to be different is because they aren't necessarily +ABI-compatible: there could be new layout optimizations, changes to MIR, or +other changes to Rust metadata on nightly that aren't present in beta.

+

This is also where --keep-stage 1 library/std comes into play. Since most +changes to the compiler don't actually change the ABI, once you've produced a +std in stage1, you can probably just reuse it with a different compiler. If +the ABI hasn't changed, you're good to go, no need to spend time recompiling +that std. The flag --keep-stage simply instructs the build script to assumes +the previous compile is fine and copies those artifacts into the appropriate +place, skipping the cargo invocation.

+

Cross-compiling rustc

+

Cross-compiling is the process of compiling code that will run on another +architecture. For instance, you might want to build an ARM version of rustc +using an x86 machine. Building stage2 std is different when you are +cross-compiling.

+

This is because ./x uses the following logic: if HOST and TARGET are the +same, it will reuse stage1 std for stage2! This is sound because stage1 +std was compiled with the stage1 compiler, i.e. a compiler using the source +code you currently have checked out. So it should be identical (and therefore +ABI-compatible) to the std that stage2/rustc would compile.

+

However, when cross-compiling, stage1 std will only run on the host. So the +stage2 compiler has to recompile std for the target.

+

(See in the table how stage2 only builds non-host std targets).

+

Why does only libstd use cfg(bootstrap)?

+

For docs on cfg(bootstrap) itself, see Complications of +Bootstrapping.

+

The rustc generated by the stage0 compiler is linked to the freshly-built +std, which means that for the most part only std needs to be cfg-gated, so +that rustc can use features added to std immediately after their addition, +without need for them to get into the downloaded beta compiler.

+

Note this is different from any other Rust program: stage1 rustc is built by +the beta compiler, but using the master version of libstd!

+

The only time rustc uses cfg(bootstrap) is when it adds internal lints that +use diagnostic items, or when it uses unstable library features that were +recently changed.

+

What is a 'sysroot'?

+

When you build a project with cargo, the build artifacts for dependencies are +normally stored in target/debug/deps. This only contains dependencies cargo +knows about; in particular, it doesn't have the standard library. Where do std +or proc_macro come from? They comes from the sysroot, the root of a number +of directories where the compiler loads build artifacts at runtime. The +sysroot doesn't just store the standard library, though - it includes anything +that needs to be loaded at runtime. That includes (but is not limited to):

+
    +
  • Libraries libstd/libtest/libproc_macro.
  • +
  • Compiler crates themselves, when using rustc_private. In-tree these are +always present; out of tree, you need to install rustc-dev with rustup.
  • +
  • Shared object file libLLVM.so for the LLVM project. In-tree this is either +built from source or downloaded from CI; out-of-tree, you need to install +llvm-tools-preview with rustup.
  • +
+

All the artifacts listed so far are compiler runtime dependencies. You can see +them with rustc --print sysroot:

+
$ ls $(rustc --print sysroot)/lib
+libchalk_derive-0685d79833dc9b2b.so  libstd-25c6acf8063a3802.so
+libLLVM-11-rust-1.50.0-nightly.so    libtest-57470d2aa8f7aa83.so
+librustc_driver-4f0cc9f50e53f0ba.so  libtracing_attributes-e4be92c35ab2a33b.so
+librustc_macros-5f0ec4a119c6ac86.so  rustlib
+
+

There are also runtime dependencies for the standard library! These are in +lib/rustlib/, not lib/ directly.

+
$ ls $(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/lib | head -n 5
+libaddr2line-6c8e02b8fedc1e5f.rlib
+libadler-9ef2480568df55af.rlib
+liballoc-9c4002b5f79ba0e1.rlib
+libcfg_if-512eb53291f6de7e.rlib
+libcompiler_builtins-ef2408da76957905.rlib
+
+

Directory lib/rustlib/ includes libraries like hashbrown and cfg_if, which +are not part of the public API of the standard library, but are used to +implement it. Also lib/rustlib/ is part of the search path for linkers, but +lib will never be part of the search path.

+

-Z force-unstable-if-unmarked

+

Since lib/rustlib/ is part of the search path we have to be careful about +which crates are included in it. In particular, all crates except for the +standard library are built with the flag -Z force-unstable-if-unmarked, which +means that you have to use #![feature(rustc_private)] in order to load it (as +opposed to the standard library, which is always available).

+

The -Z force-unstable-if-unmarked flag has a variety of purposes to help +enforce that the correct crates are marked as unstable. It was introduced +primarily to allow rustc and the standard library to link to arbitrary crates on +crates.io which do not themselves use staged_api. rustc also relies on this +flag to mark all of its crates as unstable with the rustc_private feature so +that each crate does not need to be carefully marked with unstable.

+

This flag is automatically applied to all of rustc and the standard library by +the bootstrap scripts. This is needed because the compiler and all of its +dependencies are shipped in sysroot to all users.

+

This flag has the following effects:

+
    +
  • Marks the crate as "unstable" with the rustc_private feature if it is not +itself marked as stable or unstable.
  • +
  • Allows these crates to access other forced-unstable crates without any need +for attributes. Normally a crate would need a #![feature(rustc_private)] +attribute to use other unstable crates. However, that would make it +impossible for a crate from crates.io to access its own dependencies since +that crate won't have a feature(rustc_private) attribute, but everything +is compiled with -Z force-unstable-if-unmarked.
  • +
+

Code which does not use -Z force-unstable-if-unmarked should include the +#![feature(rustc_private)] crate attribute to access these forced-unstable +crates. This is needed for things which link rustc its self, such as MIRI or +clippy.

+

You can find more discussion about sysroots in:

+ +

Passing flags to commands invoked by bootstrap

+

Conveniently ./x allows you to pass stage-specific flags to rustc and +cargo when bootstrapping. The RUSTFLAGS_BOOTSTRAP environment variable is +passed as RUSTFLAGS to the bootstrap stage (stage0), and +RUSTFLAGS_NOT_BOOTSTRAP is passed when building artifacts for later stages. +RUSTFLAGS will work, but also affects the build of bootstrap itself, so it +will be rare to want to use it. Finally, MAGIC_EXTRA_RUSTFLAGS bypasses the +cargo cache to pass flags to rustc without recompiling all dependencies.

+
    +
  • RUSTDOCFLAGS, RUSTDOCFLAGS_BOOTSTRAP and RUSTDOCFLAGS_NOT_BOOTSTRAP are +analogous to RUSTFLAGS, but for rustdoc.
  • +
  • CARGOFLAGS will pass arguments to cargo itself (e.g. --timings). +CARGOFLAGS_BOOTSTRAP and CARGOFLAGS_NOT_BOOTSTRAP work analogously to +RUSTFLAGS_BOOTSTRAP.
  • +
  • --test-args will pass arguments through to the test runner. For tests/ui, +this is compiletest. For unit tests and doc tests this is the libtest +runner.
  • +
+

Most test runner accept --help, which you can use to find out the options +accepted by the runner.

+

Environment Variables

+

During bootstrapping, there are a bunch of compiler-internal environment +variables that are used. If you are trying to run an intermediate version of +rustc, sometimes you may need to set some of these environment variables +manually. Otherwise, you get an error like the following:

+
thread 'main' panicked at 'RUSTC_STAGE was not set: NotPresent', library/core/src/result.rs:1165:5
+
+

If ./stageN/bin/rustc gives an error about environment variables, that usually +means something is quite wrong -- such as you're trying to compile rustc or +std or something which depends on environment variables. In the unlikely case +that you actually need to invoke rustc in such a situation, you can tell the +bootstrap shim to print all env variables by adding -vvv to your x +command.

+

Finally, bootstrap makes use of the cc-rs crate which has its own +method of configuring C compilers and C flags via environment +variables.

+

Clarification of build command's stdout

+

In this part, we will investigate the build command's stdout in an action +(similar, but more detailed and complete documentation compare to topic above). +When you execute x build --dry-run command, the build output will be something +like the following:

+
Building stage0 library artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
+Copying stage0 library from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
+Building stage0 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
+Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
+Assembling stage1 compiler (x86_64-unknown-linux-gnu)
+Building stage1 library artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
+Copying stage1 library from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
+Building stage1 tool rust-analyzer-proc-macro-srv (x86_64-unknown-linux-gnu)
+Building rustdoc for stage1 (x86_64-unknown-linux-gnu)
+
+

Building stage0 {std,compiler} artifacts

+

These steps use the provided (downloaded, usually) compiler to compile the local +Rust source into libraries we can use.

+

Copying stage0 {std,rustc}

+

This copies the library and compiler artifacts from cargo into +stage0-sysroot/lib/rustlib/{target-triple}/lib

+

Assembling stage1 compiler

+

This copies the libraries we built in "building stage0 ... artifacts" into the +stage1 compiler's lib/ directory. These are the host libraries that the +compiler itself uses to run. These aren't actually used by artifacts the new +compiler generates. This step also copies the rustc and rustdoc binaries we +generated into build/$HOST/stage/bin.

+

The stage1/bin/rustc is a fully functional compiler, but it doesn't yet have +any libraries to link built binaries or libraries to. The next 3 steps will +provide those libraries for it; they are mostly equivalent to constructing the +stage1/bin compiler so we don't go through them individually here.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/build-install-distribution-artifacts.html b/building/build-install-distribution-artifacts.html new file mode 100644 index 000000000..d7733849b --- /dev/null +++ b/building/build-install-distribution-artifacts.html @@ -0,0 +1,221 @@ + + + + + + Distribution artifacts - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Build distribution artifacts

+

You might want to build and package up the compiler for distribution. +You’ll want to run this command to do it:

+
./x dist
+
+

Install from source

+

You might want to prefer installing Rust (and tools configured in your configuration) +by building from source. If so, you want to run this command:

+
./x install
+
+

Note: If you are testing out a modification to a compiler, you might +want to build the compiler (with ./x build) then create a toolchain as +discussed in here.

+

For example, if the toolchain you created is called "foo", you would then +invoke it with rustc +foo ... (where ... represents the rest of the arguments).

+

Instead of installing Rust (and tools in your config file) globally, you can set DESTDIR +environment variable to change the installation path. If you want to set installation paths +more dynamically, you should prefer install options in your config file to achieve that.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/compiler-documenting.html b/building/compiler-documenting.html new file mode 100644 index 000000000..dbf3dc9d3 --- /dev/null +++ b/building/compiler-documenting.html @@ -0,0 +1,241 @@ + + + + + + Building Documentation - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Building documentation

+

This chapter describes how to build documentation of toolchain components, +like the standard library (std) or the compiler (rustc).

+
    +
  • +

    Document everything

    +

    This uses rustdoc from the beta toolchain, +so will produce (slightly) different output to stage 1 rustdoc, +as rustdoc is under active development:

    +
    ./x doc
    +
    +

    If you want to be sure the documentation looks the same as on CI:

    +
    ./x doc --stage 1
    +
    +

    This ensures that (current) rustdoc gets built, +then that is used to document the components.

    +
  • +
  • +

    Much like running individual tests or building specific components, +you can build just the documentation you want:

    +
    ./x doc src/doc/book
    +./x doc src/doc/nomicon
    +./x doc compiler library
    +
    +

    See the nightly docs index page for a full list of books.

    +
  • +
  • +

    Document internal rustc items

    +

    Compiler documentation is not built by default. +To create it by default with x doc, modify config.toml:

    +
    [build]
    +compiler-docs = true
    +
    +

    Note that when enabled, +documentation for internal compiler items will also be built.

    +

    NOTE: The documentation for the compiler is found at this link.

    +
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/how-to-build-and-run.html b/building/how-to-build-and-run.html new file mode 100644 index 000000000..15ce49ff6 --- /dev/null +++ b/building/how-to-build-and-run.html @@ -0,0 +1,543 @@ + + + + + + How to build and run the compiler - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

How to build and run the compiler

+ +

The compiler is built using a tool called x.py. You will need to +have Python installed to run it.

+

Quick Start

+

For a less in-depth quick-start of getting the compiler running, see quickstart.

+

Get the source code

+

The main repository is rust-lang/rust. This contains the compiler, +the standard library (including core, alloc, test, proc_macro, etc), +and a bunch of tools (e.g. rustdoc, the bootstrapping infrastructure, etc).

+

The very first step to work on rustc is to clone the repository:

+
git clone https://github.com/rust-lang/rust.git
+cd rust
+
+

Partial clone the repository

+

Due to the size of the repository, cloning on a slower internet connection can take a long time, +and requires disk space to store the full history of every file and directory. +Instead, it is possible to tell git to perform a partial clone, which will only fully retrieve +the current file contents, but will automatically retrieve further file contents when you, e.g., +jump back in the history. +All git commands will continue to work as usual, at the price of requiring an internet connection +to visit not-yet-loaded points in history.

+
git clone --filter='blob:none' https://github.com/rust-lang/rust.git
+cd rust
+
+
+

NOTE: This link +describes this type of checkout in more detail, and also compares it to other modes, such as +shallow cloning.

+
+

Shallow clone the repository

+

An older alternative to partial clones is to use shallow clone the repository instead. +To do so, you can use the --depth N option with the git clone command. +This instructs git to perform a "shallow clone", cloning the repository but truncating it to +the last N commits.

+

Passing --depth 1 tells git to clone the repository but truncate the history to the latest +commit that is on the master branch, which is usually fine for browsing the source code or +building the compiler.

+
git clone --depth 1 https://github.com/rust-lang/rust.git
+cd rust
+
+
+

NOTE: A shallow clone limits which git commands can be run. +If you intend to work on and contribute to the compiler, it is +generally recommended to fully clone the repository as shown above, +or to perform a partial clone instead.

+

For example, git bisect and git blame require access to the commit history, +so they don't work if the repository was cloned with --depth 1.

+
+

What is x.py?

+

x.py is the build tool for the rust repository. It can build docs, run tests, and compile the +compiler and standard library.

+

This chapter focuses on the basics to be productive, but +if you want to learn more about x.py, read this chapter.

+

Also, using x rather than x.py is recommended as:

+
+

./x is the most likely to work on every system (on Unix it runs the shell script +that does python version detection, on Windows it will probably run the +powershell script - certainly less likely to break than ./x.py which often just +opens the file in an editor).1

+
+

(You can find the platform related scripts around the x.py, like x.ps1)

+

Notice that this is not absolute. For instance, using Nushell in VSCode on Win10, +typing x or ./x still opens x.py in an editor rather than invoking the program. :)

+

In the rest of this guide, we use x rather than x.py directly. The following +command:

+
./x check
+
+

could be replaced by:

+
./x.py check
+
+

Running x.py

+

The x.py command can be run directly on most Unix systems in the following format:

+
./x <subcommand> [flags]
+
+

This is how the documentation and examples assume you are running x.py. +Some alternative ways are:

+
# On a Unix shell if you don't have the necessary `python3` command
+./x <subcommand> [flags]
+
+# In Windows Powershell (if powershell is configured to run scripts)
+./x <subcommand> [flags]
+./x.ps1 <subcommand> [flags]
+
+# On the Windows Command Prompt (if .py files are configured to run Python)
+x.py <subcommand> [flags]
+
+# You can also run Python yourself, e.g.:
+python x.py <subcommand> [flags]
+
+

On Windows, the Powershell commands may give you an error that looks like this:

+
PS C:\Users\vboxuser\rust> ./x
+./x : File C:\Users\vboxuser\rust\x.ps1 cannot be loaded because running scripts is disabled on this system. For more
+information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
+At line:1 char:1
++ ./x
++ ~~~
+    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
+    + FullyQualifiedErrorId : UnauthorizedAccess
+
+

You can avoid this error by allowing powershell to run local scripts:

+
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
+
+

Running x.py slightly more conveniently

+

There is a binary that wraps x.py called x in src/tools/x. All it does is +run x.py, but it can be installed system-wide and run from any subdirectory +of a checkout. It also looks up the appropriate version of python to use.

+

You can install it with cargo install --path src/tools/x.

+

To clarify that this is another global installed binary util, which is +similar to the one declared in section What is x.py, but +it works as an independent process to execute the x.py rather than calling the +shell to run the platform related scripts.

+

Create a config.toml

+

To start, run ./x setup and select the compiler defaults. This will do some initialization +and create a config.toml for you with reasonable defaults. If you use a different default (which +you'll likely want to do if you want to contribute to an area of rust other than the compiler, such +as rustdoc), make sure to read information about that default (located in src/bootstrap/defaults) +as the build process may be different for other defaults.

+

Alternatively, you can write config.toml by hand. See config.example.toml for all the available +settings and explanations of them. See src/bootstrap/defaults for common settings to change.

+

If you have already built rustc and you change settings related to LLVM, then you may have to +execute rm -rf build for subsequent configuration changes to take effect. Note that ./x clean will not cause a rebuild of LLVM.

+

Common x commands

+

Here are the basic invocations of the x commands most commonly used when +working on rustc, std, rustdoc, and other tools.

+
+ + + + +
CommandWhen to use it
./x checkQuick check to see if most things compile; rust-analyzer can run this automatically for you
./x buildBuilds rustc, std, and rustdoc
./x testRuns all tests
./x fmtFormats all code
+
+

As written, these commands are reasonable starting points. However, there are +additional options and arguments for each of them that are worth learning for +serious development work. In particular, ./x build and ./x test +provide many ways to compile or test a subset of the code, which can save a lot +of time.

+

Also, note that x supports all kinds of path suffixes for compiler, library, +and src/tools directories. So, you can simply run x test tidy instead of +x test src/tools/tidy. Or, x build std instead of x build library/std.

+

See the chapters on +testing and rustdoc for more details.

+

Building the compiler

+

Note that building will require a relatively large amount of storage space. +You may want to have upwards of 10 or 15 gigabytes available to build the compiler.

+

Once you've created a config.toml, you are now ready to run +x. There are a lot of options here, but let's start with what is +probably the best "go to" command for building a local compiler:

+
./x build library
+
+

This may look like it only builds the standard library, but that is not the case. +What this command does is the following:

+
    +
  • Build std using the stage0 compiler
  • +
  • Build rustc using the stage0 compiler +
      +
    • This produces the stage1 compiler
    • +
    +
  • +
  • Build std using the stage1 compiler
  • +
+

This final product (stage1 compiler + libs built using that compiler) +is what you need to build other Rust programs (unless you use #![no_std] or +#![no_core]).

+

You will probably find that building the stage1 std is a bottleneck for you, +but fear not, there is a (hacky) workaround... +see the section on avoiding rebuilds for std.

+

Sometimes you don't need a full build. When doing some kind of +"type-based refactoring", like renaming a method, or changing the +signature of some function, you can use ./x check instead for a much faster build.

+

Note that this whole command just gives you a subset of the full rustc +build. The full rustc build (what you get with ./x build --stage 2 compiler/rustc) has quite a few more steps:

+
    +
  • Build rustc with the stage1 compiler. +
      +
    • The resulting compiler here is called the "stage2" compiler.
    • +
    +
  • +
  • Build std with stage2 compiler.
  • +
  • Build librustdoc and a bunch of other things with the stage2 compiler.
  • +
+

You almost never need to do this.

+

Build specific components

+

If you are working on the standard library, you probably don't need to build +the compiler unless you are planning to use a recently added nightly feature. +Instead, you can just build using the bootstrap compiler.

+
./x build --stage 0 library
+
+

If you choose the library profile when running x setup, you can omit --stage 0 (it's the +default).

+

Creating a rustup toolchain

+

Once you have successfully built rustc, you will have created a bunch +of files in your build directory. In order to actually run the +resulting rustc, we recommend creating rustup toolchains. The first +one will run the stage1 compiler (which we built above). The second +will execute the stage2 compiler (which we did not build, but which +you will likely need to build at some point; for example, if you want +to run the entire test suite).

+
rustup toolchain link stage0 build/host/stage0-sysroot # beta compiler + stage0 std
+rustup toolchain link stage1 build/host/stage1
+rustup toolchain link stage2 build/host/stage2
+
+

Now you can run the rustc you built with. If you run with -vV, you +should see a version number ending in -dev, indicating a build from +your local environment:

+
$ rustc +stage1 -vV
+rustc 1.48.0-dev
+binary: rustc
+commit-hash: unknown
+commit-date: unknown
+host: x86_64-unknown-linux-gnu
+release: 1.48.0-dev
+LLVM version: 11.0
+
+

The rustup toolchain points to the specified toolchain compiled in your build directory, +so the rustup toolchain will be updated whenever x build or x test are run for +that toolchain/stage.

+

Note: the toolchain we've built does not include cargo. In this case, rustup will +fall back to using cargo from the installed nightly, beta, or stable toolchain +(in that order). If you need to use unstable cargo flags, be sure to run +rustup install nightly if you haven't already. See the +rustup documentation on custom toolchains.

+

Note: rust-analyzer and IntelliJ Rust plugin use a component called +rust-analyzer-proc-macro-srv to work with proc macros. If you intend to use a +custom toolchain for a project (e.g. via rustup override set stage1) you may +want to build this component:

+
./x build proc-macro-srv-cli
+
+

Building targets for cross-compilation

+

To produce a compiler that can cross-compile for other targets, +pass any number of target flags to x build. +For example, if your host platform is x86_64-unknown-linux-gnu +and your cross-compilation target is wasm32-wasip1, you can build with:

+
./x build --target x86_64-unknown-linux-gnu,wasm32-wasip1
+
+

Note that if you want the resulting compiler to be able to build crates that +involve proc macros or build scripts, you must be sure to explicitly build target support for the +host platform (in this case, x86_64-unknown-linux-gnu).

+

If you want to always build for other targets without needing to pass flags to x build, +you can configure this in the [build] section of your config.toml like so:

+
[build]
+target = ["x86_64-unknown-linux-gnu", "wasm32-wasip1"]
+
+

Note that building for some targets requires having external dependencies installed +(e.g. building musl targets requires a local copy of musl). +Any target-specific configuration (e.g. the path to a local copy of musl) +will need to be provided by your config.toml. +Please see config.example.toml for information on target-specific configuration keys.

+

For examples of the complete configuration necessary to build a target, please visit +the rustc book, +select any target under the "Platform Support" heading on the left, +and see the section related to building a compiler for that target. +For targets without a corresponding page in the rustc book, +it may be useful to inspect the Dockerfiles +that the Rust infrastructure itself uses to set up and configure cross-compilation.

+

If you have followed the directions from the prior section on creating a rustup toolchain, +then once you have built your compiler you will be able to use it to cross-compile like so:

+
cargo +stage1 build --target wasm32-wasip1
+
+

Other x commands

+

Here are a few other useful x commands. We'll cover some of them in detail +in other sections:

+
    +
  • Building things: +
      +
    • ./x build – builds everything using the stage 1 compiler, +not just up to std
    • +
    • ./x build --stage 2 – builds everything with the stage 2 compiler including +rustdoc
    • +
    +
  • +
  • Running tests (see the section on running tests for +more details): +
      +
    • ./x test library/std – runs the unit tests and integration tests from std
    • +
    • ./x test tests/ui – runs the ui test suite
    • +
    • ./x test tests/ui/const-generics - runs all the tests in +the const-generics/ subdirectory of the ui test suite
    • +
    • ./x test tests/ui/const-generics/const-types.rs - runs +the single test const-types.rs from the ui test suite
    • +
    +
  • +
+

Cleaning out build directories

+

Sometimes you need to start fresh, but this is normally not the case. +If you need to run this then bootstrap is most likely not acting right and +you should file a bug as to what is going wrong. If you do need to clean +everything up then you only need to run one command!

+
./x clean
+
+

rm -rf build works too, but then you have to rebuild LLVM, which can take +a long time even on fast computers.

+

Remarks on disk space

+

Building the compiler (especially if beyond stage 1) can require significant amounts of free disk +space, possibly around 100GB. This is compounded if you have a separate build directory for +rust-analyzer (e.g. build-rust-analyzer). This is easy to hit with dev-desktops which have a set +disk +quota +for each user, but this also applies to local development as well. Occassionally, you may need to:

+
    +
  • Remove build/ directory.
  • +
  • Remove build-rust-analyzer/ directory (if you have a separate rust-analyzer build directory).
  • +
  • Uninstall unnecessary toolchains if you use cargo-bisect-rustc. You can check which toolchains +are installed with rustup toolchain list.
  • +
+
1 +

issue#1707

+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/new-target.html b/building/new-target.html new file mode 100644 index 000000000..b29968991 --- /dev/null +++ b/building/new-target.html @@ -0,0 +1,346 @@ + + + + + + Adding a new target - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Adding a new target

+

These are a set of steps to add support for a new target. There are +numerous end states and paths to get there, so not all sections may be +relevant to your desired goal.

+ +

Specifying a new LLVM

+

For very new targets, you may need to use a different fork of LLVM +than what is currently shipped with Rust. In that case, navigate to +the src/llvm-project git submodule (you might need to run ./x check at least once so the submodule is updated), check out the +appropriate commit for your fork, then commit that new submodule +reference in the main Rust repository.

+

An example would be:

+
cd src/llvm-project
+git remote add my-target-llvm some-llvm-repository
+git checkout my-target-llvm/my-branch
+cd ..
+git add llvm-project
+git commit -m 'Use my custom LLVM'
+
+

Using pre-built LLVM

+

If you have a local LLVM checkout that is already built, you may be +able to configure Rust to treat your build as the system LLVM to avoid +redundant builds.

+

You can tell Rust to use a pre-built version of LLVM using the target section +of config.toml:

+
[target.x86_64-unknown-linux-gnu]
+llvm-config = "/path/to/llvm/llvm-7.0.1/bin/llvm-config"
+
+

If you are attempting to use a system LLVM, we have observed the following paths +before, though they may be different from your system:

+
    +
  • /usr/bin/llvm-config-8
  • +
  • /usr/lib/llvm-8/bin/llvm-config
  • +
+

Note that you need to have the LLVM FileCheck tool installed, which is used +for codegen tests. This tool is normally built with LLVM, but if you use your +own preinstalled LLVM, you will need to provide FileCheck in some other way. +On Debian-based systems, you can install the llvm-N-tools package (where N +is the LLVM version number, e.g. llvm-8-tools). Alternately, you can specify +the path to FileCheck with the llvm-filecheck config item in config.toml +or you can disable codegen test with the codegen-tests item in config.toml.

+

Creating a target specification

+

You should start with a target JSON file. You can see the specification +for an existing target using --print target-spec-json:

+
rustc -Z unstable-options --target=wasm32-unknown-unknown --print target-spec-json
+
+

Save that JSON to a file and modify it as appropriate for your target.

+

Adding a target specification

+

Once you have filled out a JSON specification and been able to compile +somewhat successfully, you can copy the specification into the +compiler itself.

+

You will need to add a line to the big table inside of the +supported_targets macro in the rustc_target::spec module. You +will then add a corresponding file for your new target containing a +target function.

+

Look for existing targets to use as examples.

+

After adding your target to the rustc_target crate you may want to add +core, std, ... with support for your new target. In that case you will +probably need access to some target_* cfg. Unfortunately when building with +stage0 (the beta compiler), you'll get an error that the target cfg is +unexpected because stage0 doesn't know about the new target specification and +we pass --check-cfg in order to tell it to check.

+

To fix the errors you will need to manually add the unexpected value to the +different Cargo.toml in library/{std,alloc,core}/Cargo.toml. Here is an +example for adding NEW_TARGET_ARCH as target_arch:

+

library/std/Cargo.toml:

+
  [lints.rust.unexpected_cfgs]
+  level = "warn"
+  check-cfg = [
+      'cfg(bootstrap)',
+-      'cfg(target_arch, values("xtensa"))',
++      # #[cfg(bootstrap)] NEW_TARGET_ARCH
++      'cfg(target_arch, values("xtensa", "NEW_TARGET_ARCH"))',
+
+

To use this target in bootstrap, we need to explicitly add the target triple to the STAGE0_MISSING_TARGETS +list in src/bootstrap/src/core/sanity.rs. This is necessary because the default compiler bootstrap uses does +not recognize the new target we just added. Therefore, it should be added to STAGE0_MISSING_TARGETS so that the +bootstrap is aware that this target is not yet supported by the stage0 compiler.

+
const STAGE0_MISSING_TARGETS: &[&str] = &[
++   "NEW_TARGET_TRIPLE"
+];
+
+

Patching crates

+

You may need to make changes to crates that the compiler depends on, +such as libc or cc. If so, you can use Cargo's +[patch] ability. For example, if you want to use an +unreleased version of libc, you can add it to the top-level +Cargo.toml file:

+
diff --git a/Cargo.toml b/Cargo.toml
+index 1e83f05e0ca..4d0172071c1 100644
+--- a/Cargo.toml
++++ b/Cargo.toml
+@@ -113,6 +113,8 @@ cargo-util = { path = "src/tools/cargo/crates/cargo-util" }
+ [patch.crates-io]
++libc = { git = "https://github.com/rust-lang/libc", rev = "0bf7ce340699dcbacabdf5f16a242d2219a49ee0" }
+
+ # See comments in `src/tools/rustc-workspace-hack/README.md` for what's going on
+ # here
+ rustc-workspace-hack = { path = 'src/tools/rustc-workspace-hack' }
+
+

After this, run cargo update -p libc to update the lockfiles.

+

Beware that if you patch to a local path dependency, this will enable +warnings for that dependency. Some dependencies are not warning-free, and due +to the deny-warnings setting in config.toml, the build may suddenly start +to fail. +To work around warnings, you may want to:

+
    +
  • Modify the dependency to remove the warnings
  • +
  • Or for local development purposes, suppress the warnings by setting deny-warnings = false in config.toml.
  • +
+
# config.toml
+[rust]
+deny-warnings = false
+
+

Cross-compiling

+

Once you have a target specification in JSON and in the code, you can +cross-compile rustc:

+
DESTDIR=/path/to/install/in \
+./x install -i --stage 1 --host aarch64-apple-darwin.json --target aarch64-apple-darwin \
+compiler/rustc library/std
+
+

If your target specification is already available in the bootstrap +compiler, you can use it instead of the JSON file for both arguments.

+

Promoting a target from tier 2 (target) to tier 2 (host)

+

There are two levels of tier 2 targets: +a) Targets that are only cross-compiled (rustup target add) +b) Targets that have a native toolchain (rustup toolchain install)

+

For an example of promoting a target from cross-compiled to native, +see #75914.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/optimized-build.html b/building/optimized-build.html new file mode 100644 index 000000000..43cb7b1c3 --- /dev/null +++ b/building/optimized-build.html @@ -0,0 +1,299 @@ + + + + + + Optimized build - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Optimized build of the compiler

+ +

There are multiple additional build configuration options and techniques that can be used to compile a +build of rustc that is as optimized as possible (for example when building rustc for a Linux +distribution). The status of these configuration options for various Rust targets is tracked here. +This page describes how you can use these approaches when building rustc yourself.

+ +

Link-time optimization is a powerful compiler technique that can increase program performance. To +enable (Thin-)LTO when building rustc, set the rust.lto config option to "thin" +in config.toml:

+
[rust]
+lto = "thin"
+
+
+

Note that LTO for rustc is currently supported and tested only for +the x86_64-unknown-linux-gnu target. Other targets may work, but no guarantees are provided. +Notably, LTO-optimized rustc currently produces miscompilations on Windows.

+
+

Enabling LTO on Linux has produced speed-ups by up to 10%.

+

Memory allocator

+

Using a different memory allocator for rustc can provide significant performance benefits. If you +want to enable the jemalloc allocator, you can set the rust.jemalloc option to true +in config.toml:

+
[rust]
+jemalloc = true
+
+
+

Note that this option is currently only supported for Linux and macOS targets.

+
+

Codegen units

+

Reducing the amount of codegen units per rustc crate can produce a faster build of the compiler. +You can modify the number of codegen units for rustc and libstd in config.toml with the +following options:

+
[rust]
+codegen-units = 1
+codegen-units-std = 1
+
+

Instruction set

+

By default, rustc is compiled for a generic (and conservative) instruction set architecture +(depending on the selected target), to make it support as many CPUs as possible. If you want to +compile rustc for a specific instruction set architecture, you can set the target_cpu compiler +option in RUSTFLAGS:

+
RUSTFLAGS="-C target_cpu=x86-64-v3" ./x build ...
+
+

If you also want to compile LLVM for a specific instruction set, you can set llvm flags +in config.toml:

+
[llvm]
+cxxflags = "-march=x86-64-v3"
+cflags = "-march=x86-64-v3"
+
+

Profile-guided optimization

+

Applying profile-guided optimizations (or more generally, feedback-directed optimizations) can +produce a large increase to rustc performance, by up to 15% (1, 2). However, these techniques +are not simply enabled by a configuration option, but rather they require a complex build workflow +that compiles rustc multiple times and profiles it on selected benchmarks.

+

There is a tool called opt-dist that is used to optimize rustc with PGO (profile-guided +optimizations) and BOLT (a post-link binary optimizer) for builds distributed to end users. You +can examine the tool, which is located in src/tools/opt-dist, and build a custom PGO build +workflow based on it, or try to use it directly. Note that the tool is currently quite hardcoded to +the way we use it in Rust's continuous integration workflows, and it might require some custom +changes to make it work in a different environment.

+

To use the tool, you will need to provide some external dependencies:

+
    +
  • A Python3 interpreter (for executing x.py).
  • +
  • Compiled LLVM toolchain, with the llvm-profdata binary. Optionally, if you want to use BOLT, +the llvm-bolt and +merge-fdata binaries have to be available in the toolchain.
  • +
+

These dependencies are provided to opt-dist by an implementation of the Environment struct. +It specifies directories where will the PGO/BOLT pipeline take place, and also external dependencies +like Python or LLVM.

+

Here is an example of how can opt-dist be used locally (outside of CI):

+
    +
  1. Build the tool with the following command: +
    ./x build tools/opt-dist
    +
    +
  2. +
  3. Run the tool with the local mode and provide necessary parameters: +
    ./build/host/stage0-tools-bin/opt-dist local \
    +  --target-triple <target> \ # select target, e.g. "x86_64-unknown-linux-gnu"
    +  --checkout-dir <path>    \ # path to rust checkout, e.g. "."
    +  --llvm-dir <path>        \ # path to built LLVM toolchain, e.g. "/foo/bar/llvm/install"
    +  -- python3 x.py dist       # pass the actual build command
    +
    +You can run --help to see further parameters that you can modify.
  4. +
+
+

Note: if you want to run the actual CI pipeline, instead of running opt-dist locally, +you can execute DEPLOY=1 src/ci/docker/run.sh dist-x86_64-linux.

+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/prerequisites.html b/building/prerequisites.html new file mode 100644 index 000000000..83702fefe --- /dev/null +++ b/building/prerequisites.html @@ -0,0 +1,235 @@ + + + + + + Prerequisites - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Prerequisites

+

Dependencies

+

See the rust-lang/rust INSTALL.

+

Hardware

+

You will need an internet connection to build. The bootstrapping process +involves updating git submodules and downloading a beta compiler. It doesn't +need to be super fast, but that can help.

+

There are no strict hardware requirements, but building the compiler is +computationally expensive, so a beefier machine will help, and I wouldn't +recommend trying to build on a Raspberry Pi! We recommend the following.

+
    +
  • 30GB+ of free disk space. Otherwise, you will have to keep +clearing incremental caches. More space is better, the compiler is a bit of a +hog; it's a problem we are aware of.
  • +
  • 8GB+ RAM
  • +
  • 2+ cores. Having more cores really helps. 10 or 20 or more is not too many!
  • +
+

Beefier machines will lead to much faster builds. If your machine is not very +powerful, a common strategy is to only use ./x check on your local machine +and let the CI build test your changes when you push to a PR branch.

+

Building the compiler takes more than half an hour on my moderately powerful +laptop. We suggest downloading LLVM from CI so you don't have to build it from source +(see here).

+

Like cargo, the build system will use as many cores as possible. Sometimes +this can cause you to run low on memory. You can use -j to adjust the number +of concurrent jobs. If a full build takes more than ~45 minutes to an hour, you +are probably spending most of the time swapping memory in and out; try using +-j1.

+

If you don't have too much free disk space, you may want to turn off +incremental compilation (see here). This will make compilation take +longer (especially after a rebase), but will save a ton of space from the +incremental caches.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/quickstart.html b/building/quickstart.html new file mode 100644 index 000000000..b580d15c5 --- /dev/null +++ b/building/quickstart.html @@ -0,0 +1,254 @@ + + + + + + Quickstart - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Quickstart

+

This is a quickstart guide about getting the compiler running. For more +information on the individual steps, see the other pages in this chapter.

+

First, clone the repository:

+
git clone https://github.com/rust-lang/rust.git
+cd rust
+
+

When building the compiler, we don't use cargo directly, instead we use a +wrapper called "x". It is invoked with ./x.

+

We need to create a configuration for the build. Use ./x setup to create a +good default.

+
./x setup
+
+

Then, we can build the compiler. Use ./x build to build the compiler, standard +library and a few tools. You can also ./x check to just check it. All these +commands can take specific components/paths as arguments, for example ./x check compiler to just check the compiler.

+
./x build
+
+
+

When doing a change to the compiler that does not affect the way it compiles +the standard library (so for example, a change to an error message), use +--keep-stage-std 1 to avoid recompiling it.

+
+

After building the compiler and standard library, you now have a working +compiler toolchain. You can use it with rustup by linking it.

+
rustup toolchain link stage1 build/host/stage1
+
+

Now you have a toolchain called stage1 linked to your build. You can use it to +test the compiler.

+
rustc +stage1 testfile.rs
+
+

After doing a change, you can run the compiler test suite with ./x test.

+

./x test runs the full test suite, which is slow and rarely what you want. +Usually, ./x test tests/ui is what you want after a compiler change, testing +all UI tests that invoke the compiler on a specific test file +and check the output.

+
./x test tests/ui
+
+

Use --bless if you've made a change and want to update the .stderr files +with the new output.

+
+

./x suggest can also be helpful for suggesting which tests to run after a +change.

+
+

Congrats, you are now ready to make a change to the compiler! If you have more +questions, the full chapter might contain the +answers, and if it doesn't, feel free to ask for help on +Zulip.

+

If you use VSCode, Vim, Emacs or Helix, ./x setup will ask you if you want to +set up the editor config. For more information, check out suggested +workflows.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/building/suggested.html b/building/suggested.html new file mode 100644 index 000000000..d4be31436 --- /dev/null +++ b/building/suggested.html @@ -0,0 +1,526 @@ + + + + + + Suggested Workflows - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Suggested Workflows

+

The full bootstrapping process takes quite a while. Here are some suggestions to +make your life easier.

+ +

Installing a pre-push hook

+

CI will automatically fail your build if it doesn't pass tidy, our internal +tool for ensuring code quality. If you'd like, you can install a Git +hook that will +automatically run ./x test tidy on each push, to ensure your code is up to +par. If the hook fails then run ./x test tidy --bless and commit the changes. +If you decide later that the pre-push behavior is undesirable, you can delete +the pre-push file in .git/hooks.

+

A prebuilt git hook lives at src/etc/pre-push.sh. It can be copied into +your .git/hooks folder as pre-push (without the .sh extension!).

+

You can also install the hook as a step of running ./x setup!

+

Configuring rust-analyzer for rustc

+

Project-local rust-analyzer setup

+

rust-analyzer can help you check and format your code whenever you save a +file. By default, rust-analyzer runs the cargo check and rustfmt commands, +but you can override these commands to use more adapted versions of these tools +when hacking on rustc. With custom setup, rust-analyzer can use ./x check +to check the sources, and the stage 0 rustfmt to format them.

+

The default rust-analyzer.check.overrideCommand command line will check all +the crates and tools in the repository. If you are working on a specific part, +you can override the command to only check the part you are working on to save +checking time. For example, if you are working on the compiler, you can override +the command to x check compiler --json-output to only check the compiler part. +You can run x check --help --verbose to see the available parts.

+

Running ./x setup editor will prompt you to create a project-local LSP config +file for one of the supported editors. You can also create the config file as a +step of running ./x setup.

+

Using a separate build directory for rust-analyzer

+

By default, when rust-analyzer runs a check or format command, it will share +the same build directory as manual command-line builds. This can be inconvenient +for two reasons:

+
    +
  • Each build will lock the build directory and force the other to wait, so it +becomes impossible to run command-line builds while rust-analyzer is running +commands in the background.
  • +
  • There is an increased risk of one of the builds deleting previously-built +artifacts due to conflicting compiler flags or other settings, forcing +additional rebuilds in some cases.
  • +
+

To avoid these problems:

+
    +
  • Add --build-dir=build-rust-analyzer to all of the custom x commands in +your editor's rust-analyzer configuration. +(Feel free to choose a different directory name if desired.)
  • +
  • Modify the rust-analyzer.rustfmt.overrideCommand setting so that it points +to the copy of rustfmt in that other build directory.
  • +
  • Modify the rust-analyzer.procMacro.server setting so that it points to the +copy of rust-analyzer-proc-macro-srv in that other build directory.
  • +
+

Using separate build directories for command-line builds and rust-analyzer +requires extra disk space, and also means that running ./x clean on the +command-line will not clean out the separate build directory. To clean the +separate build directory, run ./x clean --build-dir=build-rust-analyzer +instead.

+

Visual Studio Code

+

Selecting vscode in ./x setup editor will prompt you to create a +.vscode/settings.json file which will configure Visual Studio code. The +recommended rust-analyzer settings live at +src/etc/rust_analyzer_settings.json.

+

If running ./x check on save is inconvenient, in VS Code you can use a Build +Task instead:

+
// .vscode/tasks.json
+{
+    "version": "2.0.0",
+    "tasks": [
+        {
+            "label": "./x check",
+            "command": "./x check",
+            "type": "shell",
+            "problemMatcher": "$rustc",
+            "presentation": { "clear": true },
+            "group": { "kind": "build", "isDefault": true }
+        }
+    ]
+}
+
+

Neovim

+

For Neovim users there are several options for configuring for rustc. The +easiest way is by using neoconf.nvim, +which allows for project-local configuration files with the native LSP. The +steps for how to use it are below. Note that they require rust-analyzer to +already be configured with Neovim. Steps for this can be found +here.

+
    +
  1. First install the plugin. This can be done by following the steps in the +README.
  2. +
  3. Run ./x setup editor, and select vscode to create a +.vscode/settings.json file. neoconf is able to read and update +rust-analyzer settings automatically when the project is opened when this +file is detected.
  4. +
+

If you're using coc.nvim, you can run ./x setup editor and select vim to +create a .vim/coc-settings.json. The settings can be edited with +:CocLocalConfig. The recommended settings live at +src/etc/rust_analyzer_settings.json.

+

Another way is without a plugin, and creating your own logic in your +configuration. To do this you must translate the JSON to Lua yourself. The +translation is 1:1 and fairly straight-forward. It must be put in the +["rust-analyzer"] key of the setup table, which is shown +here.

+

If you would like to use the build task that is described above, you may either +make your own command in your config, or you can install a plugin such as +overseer.nvim that can read +VSCode's task.json +files, +and follow the same instructions as above.

+

Emacs

+

Emacs provides support for rust-analyzer with project-local configuration +through Eglot.
+Steps for setting up Eglot with rust-analyzer can be found +here.
+Having set up Emacs & Eglot for Rust development in general, you can run +./x setup editor and select emacs, which will prompt you to create +.dir-locals.el with the recommended configuration for Eglot. +The recommended settings live at src/etc/rust_analyzer_eglot.el.
+For more information on project-specific Eglot configuration, consult the +manual.

+

Helix

+

Helix comes with built-in LSP and rust-analyzer support.
+It can be configured through languages.toml, as described +here.
+You can run ./x setup editor and select helix, which will prompt you to +create languages.toml with the recommended configuration for Helix. The +recommended settings live at src/etc/rust_analyzer_helix.toml.

+

Check, check, and check again

+

When doing simple refactoring, it can be useful to run ./x check +continuously. If you set up rust-analyzer as described above, this will be +done for you every time you save a file. Here you are just checking that the +compiler can build, but often that is all you need (e.g., when renaming a +method). You can then run ./x build when you actually need to run tests.

+

In fact, it is sometimes useful to put off tests even when you are not 100% sure +the code will work. You can then keep building up refactoring commits and only +run the tests at some later time. You can then use git bisect to track down +precisely which commit caused the problem. A nice side-effect of this style +is that you are left with a fairly fine-grained set of commits at the end, all +of which build and pass tests. This often helps reviewing.

+

x suggest

+

The x suggest subcommand suggests (and runs) a subset of the extensive +rust-lang/rust tests based on files you have changed. This is especially +useful for new contributors who have not mastered the arcane x flags yet and +more experienced contributors as a shorthand for reducing mental effort. In all +cases it is useful not to run the full tests (which can take on the order of +tens of minutes) and just run a subset which are relevant to your changes. For +example, running tidy and linkchecker is useful when editing Markdown files, +whereas UI tests are much less likely to be helpful. While x suggest is a +useful tool, it does not guarantee perfect coverage (just as PR CI isn't a +substitute for bors). See the dedicated chapter for +more information and contribution instructions.

+

Please note that x suggest is in a beta state currently and the tests that it +will suggest are limited.

+

Configuring rustup to use nightly

+

Some parts of the bootstrap process uses pinned, nightly versions of tools like +rustfmt. To make things like cargo fmt work correctly in your repo, run

+
cd <path to rustc repo>
+rustup override set nightly
+
+

after installing a nightly toolchain with rustup. Don't forget to do this +for all directories you have setup a worktree for. You may need to use the +pinned nightly version from src/stage0, but often the normal nightly channel +will work.

+

Note see the section on vscode for how to configure it with this real +rustfmt x uses, and the section on rustup for how to setup rustup +toolchain for your bootstrapped compiler

+

Note This does not allow you to build rustc with cargo directly. You +still have to use x to work on the compiler or standard library, this just +lets you use cargo fmt.

+

Faster builds with --keep-stage.

+

Sometimes just checking whether the compiler builds is not enough. A common +example is that you need to add a debug! statement to inspect the value of +some state or better understand the problem. In that case, you don't really need +a full build. By bypassing bootstrap's cache invalidation, you can often get +these builds to complete very fast (e.g., around 30 seconds). The only catch is +this requires a bit of fudging and may produce compilers that don't work (but +that is easily detected and fixed).

+

The sequence of commands you want is as follows:

+
    +
  • Initial build: ./x build library +
      +
    • As documented previously, this will build a functional stage1 compiler as +part of running all stage0 commands (which include building a std +compatible with the stage1 compiler) as well as the first few steps of the +"stage 1 actions" up to "stage1 (sysroot stage1) builds std".
    • +
    +
  • +
  • Subsequent builds: ./x build library --keep-stage 1 +
      +
    • Note that we added the --keep-stage 1 flag here
    • +
    +
  • +
+

As mentioned, the effect of --keep-stage 1 is that we just assume that the +old standard library can be re-used. If you are editing the compiler, this is +almost always true: you haven't changed the standard library, after all. But +sometimes, it's not true: for example, if you are editing the "metadata" part of +the compiler, which controls how the compiler encodes types and other states +into the rlib files, or if you are editing things that wind up in the metadata +(such as the definition of the MIR).

+

The TL;DR is that you might get weird behavior from a compile when using +--keep-stage 1 -- for example, strange ICEs +or other panics. In that case, you should simply remove the --keep-stage 1 +from the command and rebuild. That ought to fix the problem.

+

You can also use --keep-stage 1 when running tests. Something like this:

+
    +
  • Initial test run: ./x test tests/ui
  • +
  • Subsequent test run: ./x test tests/ui --keep-stage 1
  • +
+

Using incremental compilation

+

You can further enable the --incremental flag to save additional time in +subsequent rebuilds:

+
./x test tests/ui --incremental --test-args issue-1234
+
+

If you don't want to include the flag with every command, you can enable it in +the config.toml:

+
[rust]
+incremental = true
+
+

Note that incremental compilation will use more disk space than usual. If disk +space is a concern for you, you might want to check the size of the build +directory from time to time.

+

Fine-tuning optimizations

+

Setting optimize = false makes the compiler too slow for tests. However, to +improve the test cycle, you can disable optimizations selectively only for the +crates you'll have to rebuild +(source). +For example, when working on rustc_mir_build, the rustc_mir_build and +rustc_driver crates take the most time to incrementally rebuild. You could +therefore set the following in the root Cargo.toml:

+
[profile.release.package.rustc_mir_build]
+opt-level = 0
+[profile.release.package.rustc_driver]
+opt-level = 0
+
+

Working on multiple branches at the same time

+

Working on multiple branches in parallel can be a little annoying, since +building the compiler on one branch will cause the old build and the incremental +compilation cache to be overwritten. One solution would be to have multiple +clones of the repository, but that would mean storing the Git metadata multiple +times, and having to update each clone individually.

+

Fortunately, Git has a better solution called worktrees. This lets you create +multiple "working trees", which all share the same Git database. Moreover, +because all of the worktrees share the same object database, if you update a +branch (e.g. master) in any of them, you can use the new commits from any of the +worktrees. One caveat, though, is that submodules do not get shared. They will +still be cloned multiple times.

+

Given you are inside the root directory for your Rust repository, you can create +a "linked working tree" in a new "rust2" directory by running the following +command:

+
git worktree add ../rust2
+
+

Creating a new worktree for a new branch based on master looks like:

+
git worktree add -b my-feature ../rust2 master
+
+

You can then use that rust2 folder as a separate workspace for modifying and +building rustc!

+

Using nix-shell

+

If you're using nix, you can use the following nix-shell to work on Rust:

+
{ pkgs ? import <nixpkgs> {} }:
+pkgs.mkShell {
+  name = "rustc";
+  nativeBuildInputs = with pkgs; [
+    binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
+  ];
+  buildInputs = with pkgs; [
+    openssl glibc.out glibc.static
+  ];
+  # Avoid creating text files for ICEs.
+  RUSTC_ICE = "0";
+  # Provide `libstdc++.so.6` for the self-contained lld.
+  LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [
+    stdenv.cc.cc.lib
+  ]}";
+}
+
+

Note that when using nix on a not-NixOS distribution, it may be necessary to set +patch-binaries-for-nix = true in config.toml. Bootstrap tries to detect +whether it's running in nix and enable patching automatically, but this +detection can have false negatives.

+

You can also use your nix shell to manage config.toml:

+
let
+  config = pkgs.writeText "rustc-config" ''
+    # Your config.toml content goes here
+  ''
+pkgs.mkShell {
+  /* ... */
+  # This environment variable tells bootstrap where our config.toml is.
+  RUST_BOOTSTRAP_CONFIG = config;
+}
+
+

Shell Completions

+

If you use Bash, Fish or PowerShell, you can find automatically-generated shell +completion scripts for x.py in +src/etc/completions. +Zsh support will also be included once issues with +clap_complete have been resolved.

+

You can use source ./src/etc/completions/x.py.<extension> to load completions +for your shell of choice, or & .\src\etc\completions\x.py.ps1 for PowerShell. +Adding this to your shell's startup script (e.g. .bashrc) will automatically +load this completion.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/cli.html b/cli.html new file mode 100644 index 000000000..b1828455d --- /dev/null +++ b/cli.html @@ -0,0 +1,228 @@ + + + + + + Command-line arguments - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Command-line Arguments

+

Command-line flags are documented in the rustc book. All stable +flags should be documented there. Unstable flags should be documented in the +unstable book.

+

See the forge guide for new options for details on the procedure for +adding a new command-line argument.

+

Guidelines

+
    +
  • Flags should be orthogonal to each other. For example, if we'd have a +json-emitting variant of multiple actions foo and bar, an additional +--json flag is better than adding --foo-json and --bar-json.
  • +
  • Avoid flags with the no- prefix. Instead, use the parse_bool function, +such as -C embed-bitcode=no.
  • +
  • Consider the behavior if the flag is passed multiple times. In some +situations, the values should be accumulated (in order!). In other +situations, subsequent flags should override previous flags (for example, +the lint-level flags). And some flags (like -o) should generate an error +if it is too ambiguous what multiple flags would mean.
  • +
  • Always give options a long descriptive name, if only for more understandable +compiler scripts.
  • +
  • The --verbose flag is for adding verbose information to rustc +output. For example, using it with the --version +flag gives information about the hashes of the compiler code.
  • +
  • Experimental flags and options must be guarded behind the -Z unstable-options flag.
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/clipboard.min.js b/clipboard.min.js new file mode 100644 index 000000000..02c549e35 --- /dev/null +++ b/clipboard.min.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v2.0.4 + * https://zenorocha.github.io/clipboard.js + * + * Licensed MIT © Zeno Rocha + */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return function(n){var o={};function r(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}return r.m=n,r.c=o,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function o(t,e){for(var n=0;n + + + + + Closure expansion - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Closure Expansion in rustc

+

This section describes how rustc handles closures. Closures in Rust are +effectively "desugared" into structs that contain the values they use (or +references to the values they use) from their creator's stack frame. rustc has +the job of figuring out which values a closure uses and how, so it can decide +whether to capture a given variable by shared reference, mutable reference, or +by move. rustc also has to figure out which of the closure traits (Fn, +FnMut, or FnOnce) a closure is capable of +implementing.

+

Let's start with a few examples:

+

Example 1

+

To start, let's take a look at how the closure in the following example is desugared:

+
fn closure(f: impl Fn()) {
+    f();
+}
+
+fn main() {
+    let x: i32 = 10;
+    closure(|| println!("Hi {}", x));  // The closure just reads x.
+    println!("Value of x after return {}", x);
+}
+
+

Let's say the above is the content of a file called immut.rs. If we compile +immut.rs using the following command. The -Z dump-mir=all flag will cause +rustc to generate and dump the MIR to a directory called mir_dump.

+
> rustc +stage1 immut.rs -Z dump-mir=all
+
+

After we run this command, we will see a newly generated directory in our +current working directory called mir_dump, which will contain several files. +If we look at file rustc.main.-------.mir_map.0.mir, we will find, among +other things, it also contains this line:

+
_4 = &_1;
+_3 = [closure@immut.rs:7:13: 7:36] { x: move _4 };
+
+

Note that in the MIR examples in this chapter, _1 is x.

+

Here in first line _4 = &_1;, the mir_dump tells us that x was borrowed +as an immutable reference. This is what we would hope as our closure just +reads x.

+

Example 2

+

Here is another example:

+
fn closure(mut f: impl FnMut()) {
+    f();
+}
+
+fn main() {
+    let mut x: i32 = 10;
+    closure(|| {
+        x += 10;  // The closure mutates the value of x
+        println!("Hi {}", x)
+    });
+    println!("Value of x after return {}", x);
+}
+
+
_4 = &mut _1;
+_3 = [closure@mut.rs:7:13: 10:6] { x: move _4 };
+
+

This time along, in the line _4 = &mut _1;, we see that the borrow is changed to mutable borrow. +Fair enough! The closure increments x by 10.

+

Example 3

+

One more example:

+
fn closure(f: impl FnOnce()) {
+    f();
+}
+
+fn main() {
+    let x = vec![21];
+    closure(|| {
+        drop(x);  // Makes x unusable after the fact.
+    });
+    // println!("Value of x after return {:?}", x);
+}
+
+
_6 = [closure@move.rs:7:13: 9:6] { x: move _1 }; // bb16[3]: scope 1 at move.rs:7:13: 9:6
+
+

Here, x is directly moved into the closure and the access to it will not be permitted after the +closure.

+

Inferences in the compiler

+

Now let's dive into rustc code and see how all these inferences are done by the compiler.

+

Let's start with defining a term that we will be using quite a bit in the rest of the discussion - +upvar. An upvar is a variable that is local to the function where the closure is defined. So, +in the above examples, x will be an upvar to the closure. They are also sometimes referred to as +the free variables meaning they are not bound to the context of the closure. +compiler/rustc_passes/src/upvars.rs defines a query called upvars_mentioned +for this purpose.

+

Other than lazy invocation, one other thing that distinguishes a closure from a +normal function is that it can use the upvars. It borrows these upvars from its surrounding +context; therefore the compiler has to determine the upvar's borrow type. The compiler starts with +assigning an immutable borrow type and lowers the restriction (that is, changes it from +immutable to mutable to move) as needed, based on the usage. In the Example 1 above, the +closure only uses the variable for printing but does not modify it in any way and therefore, in the +mir_dump, we find the borrow type for the upvar x to be immutable. In example 2, however, the +closure modifies x and increments it by some value. Because of this mutation, the compiler, which +started off assigning x as an immutable reference type, has to adjust it as a mutable reference. +Likewise in the third example, the closure drops the vector and therefore this requires the variable +x to be moved into the closure. Depending on the borrow kind, the closure has to implement the +appropriate trait: Fn trait for immutable borrow, FnMut for mutable borrow, +and FnOnce for move semantics.

+

Most of the code related to the closure is in the +compiler/rustc_hir_typeck/src/upvar.rs file and the data structures are +declared in the file compiler/rustc_middle/src/ty/mod.rs.

+

Before we go any further, let's discuss how we can examine the flow of control through the rustc +codebase. For closures specifically, set the RUSTC_LOG env variable as below and collect the +output in a file:

+
> RUSTC_LOG=rustc_hir_typeck::upvar rustc +stage1 -Z dump-mir=all \
+    <.rs file to compile> 2> <file where the output will be dumped>
+
+

This uses the stage1 compiler and enables debug! logging for the +rustc_hir_typeck::upvar module.

+

The other option is to step through the code using lldb or gdb.

+
    +
  1. rust-lldb build/host/stage1/bin/rustc test.rs
  2. +
  3. In lldb: +
      +
    1. b upvar.rs:134 // Setting the breakpoint on a certain line in the upvar.rs file`
    2. +
    3. r // Run the program until it hits the breakpoint
    4. +
    +
  4. +
+

Let's start with upvar.rs. This file has something called +the euv::ExprUseVisitor which walks the source of the closure and +invokes a callback for each upvar that is borrowed, mutated, or moved.

+
fn main() {
+    let mut x = vec![21];
+    let _cl = || {
+        let y = x[0];  // 1.
+        x[0] += 1;  // 2.
+    };
+}
+
+

In the above example, our visitor will be called twice, for the lines marked 1 and 2, once for a +shared borrow and another one for a mutable borrow. It will also tell us what was borrowed.

+

The callbacks are defined by implementing the Delegate trait. The +InferBorrowKind type implements Delegate and keeps a map that +records for each upvar which mode of capture was required. The modes of capture +can be ByValue (moved) or ByRef (borrowed). For ByRef borrows, the possible +BorrowKinds are ImmBorrow, UniqueImmBorrow, MutBorrow as defined in the +compiler/rustc_middle/src/ty/mod.rs.

+

Delegate defines a few different methods (the different callbacks): +consume for move of a variable, borrow for a borrow of some kind +(shared or mutable), and mutate when we see an assignment of something.

+

All of these callbacks have a common argument cmt which stands for Category, +Mutability and Type and is defined in +compiler/rustc_hir_typeck/src/expr_use_visitor.rs. Borrowing from the code +comments, "cmt is a complete categorization of a value indicating where it +originated and how it is located, as well as the mutability of the memory in +which the value is stored". Based on the callback (consume, borrow etc.), we +will call the relevant adjust_upvar_borrow_kind_for_<something> and pass the +cmt along. Once the borrow type is adjusted, we store it in the table, which +basically says what borrows were made for each closure.

+
self.tables
+    .borrow_mut()
+    .upvar_capture_map
+    .extend(delegate.adjust_upvar_captures);
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/coherence.html b/coherence.html new file mode 100644 index 000000000..27f365319 --- /dev/null +++ b/coherence.html @@ -0,0 +1,272 @@ + + + + + + Coherence Checking - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Coherence

+
+

NOTE: this is based on notes by @lcnr

+
+

Coherence checking is what detects both of trait impls and inherent impls overlapping with others. +(reminder: inherent impls are impls of concrete types like impl MyStruct {})

+

Overlapping trait impls always produce an error, +while overlapping inherent impls result in an error only if they have methods with the same name.

+

Checking for overlaps is split in two parts. First there's the overlap check(s), +which finds overlaps between traits and inherent implementations that the compiler currently knows about.

+

However, Coherence also results in an error if any other impls could exist, +even if they are currently unknown. +This affects impls which may get added to upstream crates in a backwards compatible way, +and impls from downstream crates. +This is called the Orphan check.

+

Overlap checks

+

Overlap checks are performed for both inherent impls, and for trait impls. +This uses the same overlap checking code, really done as two separate analyses. +Overlap checks always consider pairs of implementations, comparing them to each other.

+

Overlap checking for inherent impl blocks is done through fn check_item in coherence/inherent_impls_overlap.rs), +where you can very clearly see that (at least for small n), the check really performs n^2 +comparisons between impls.

+

In the case of traits, this check is currently done as part of building the specialization graph, +to handle specializing impls overlapping with their parent, but this may change in the future.

+

In both cases, all pairs of impls are checked for overlap.

+

Overlapping is sometimes partially allowed:

+
    +
  1. for marker traits
  2. +
  3. under specialization
  4. +
+

but normally isn't.

+

The overlap check has various modes (see OverlapMode). +Importantly, there's the explicit negative impl check, and the implicit negative impl check. +Both try to prove that an overlap is definitely impossible.

+

The explicit negative impl check

+

This check is done in impl_intersection_has_negative_obligation.

+

This check tries to find a negative trait implementation. +For example:

+
#![allow(unused)]
+fn main() {
+struct MyCustomErrorType;
+
+// both in your own crate
+impl From<&str> for MyCustomErrorType {}
+impl<E> From<E> for MyCustomErrorType where E: Error {}
+}
+
+

In this example, we'd get: +MyCustomErrorType: From<&str> and MyCustomErrorType: From<?E>, giving ?E = &str.

+

And thus, these two implementations would overlap. +However, libstd provides &str: !Error, and therefore guarantees that there +will never be a positive implementation of &str: Error, and thus there is no overlap.

+

Note that for this kind of negative impl check, we must have explicit negative implementations provided. +This is not currently stable.

+

The implicit negative impl check

+

This check is done in impl_intersection_has_impossible_obligation, +and does not rely on negative trait implementations and is stable.

+

Let's say there's a

+
#![allow(unused)]
+fn main() {
+impl From<MyLocalType> for Box<dyn Error> {}  // in your own crate
+impl<E> From<E> for Box<dyn Error> where E: Error {} // in std
+}
+
+

This would give: Box<dyn Error>: From<MyLocalType>, and Box<dyn Error>: From<?E>,
+giving ?E = MyLocalType.

+

In your crate there's no MyLocalType: Error, downstream crates cannot implement Error (a remote trait) for MyLocalType (a remote type). +Therefore, these two impls do not overlap. +Importantly, this works even if there isn't a impl !Error for MyLocalType.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/compiler-debugging.html b/compiler-debugging.html new file mode 100644 index 000000000..a98a0c8bb --- /dev/null +++ b/compiler-debugging.html @@ -0,0 +1,536 @@ + + + + + + Debugging the compiler - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Debugging the compiler

+ +

This chapter contains a few tips to debug the compiler. These tips aim to be +useful no matter what you are working on. Some of the other chapters have +advice about specific parts of the compiler (e.g. the Queries Debugging and +Testing chapter or the LLVM Debugging +chapter).

+

Configuring the compiler

+

By default, rustc is built without most debug information. To enable debug info, +set debug = true in your config.toml.

+

Setting debug = true turns on many different debug options (e.g., debug-assertions, +debug-logging, etc.) which can be individually tweaked if you want to, but many people +simply set debug = true.

+

If you want to use GDB to debug rustc, please set config.toml with options:

+
[rust]
+debug = true
+debuginfo-level = 2
+
+
+

NOTE: +This will use a lot of disk space +(upwards of 35GB), +and will take a lot more compile time. +With debuginfo-level = 1 (the default when debug = true), +you will be able to track the execution path, +but will lose the symbol information for debugging.

+
+

The default configuration will enable symbol-mangling-version v0. +This requires at least GDB v10.2, +otherwise you need to disable new symbol-mangling-version in config.toml.

+
[rust]
+new-symbol-mangling = false
+
+
+

See the comments in config.example.toml for more info.

+
+

You will need to rebuild the compiler after changing any configuration option.

+

Suppressing the ICE file

+

By default, if rustc encounters an Internal Compiler Error (ICE) it will dump the ICE contents to an +ICE file within the current working directory named rustc-ice-<timestamp>-<pid>.txt. If this is +not desirable, you can prevent the ICE file from being created with RUSTC_ICE=0.

+

Getting a backtrace

+

When you have an ICE (panic in the compiler), you can set +RUST_BACKTRACE=1 to get the stack trace of the panic! like in +normal Rust programs. IIRC backtraces don't work on MinGW, +sorry. If you have trouble or the backtraces are full of unknown, +you might want to find some way to use Linux, Mac, or MSVC on Windows.

+

In the default configuration (without debug set to true), you don't have line numbers +enabled, so the backtrace looks like this:

+
stack backtrace:
+   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
+   1: std::sys_common::backtrace::_print
+   2: std::panicking::default_hook::{{closure}}
+   3: std::panicking::default_hook
+   4: std::panicking::rust_panic_with_hook
+   5: std::panicking::begin_panic
+   (~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
+  32: rustc_typeck::check_crate
+  33: <std::thread::local::LocalKey<T>>::with
+  34: <std::thread::local::LocalKey<T>>::with
+  35: rustc::ty::context::TyCtxt::create_and_enter
+  36: rustc_driver::driver::compile_input
+  37: rustc_driver::run_compiler
+
+

If you set debug = true, you will get line numbers for the stack trace. +Then the backtrace will look like this:

+
stack backtrace:
+   (~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
+             at /home/user/rust/compiler/rustc_typeck/src/check/cast.rs:110
+   7: rustc_typeck::check::cast::CastCheck::check
+             at /home/user/rust/compiler/rustc_typeck/src/check/cast.rs:572
+             at /home/user/rust/compiler/rustc_typeck/src/check/cast.rs:460
+             at /home/user/rust/compiler/rustc_typeck/src/check/cast.rs:370
+   (~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
+  33: rustc_driver::driver::compile_input
+             at /home/user/rust/compiler/rustc_driver/src/driver.rs:1010
+             at /home/user/rust/compiler/rustc_driver/src/driver.rs:212
+  34: rustc_driver::run_compiler
+             at /home/user/rust/compiler/rustc_driver/src/lib.rs:253
+
+

-Z flags

+

The compiler has a bunch of -Z * flags. These are unstable flags that are only +enabled on nightly. Many of them are useful for debugging. To get a full listing +of -Z flags, use -Z help.

+

One useful flag is -Z verbose-internals, which generally enables printing more +info that could be useful for debugging.

+

Right below you can find elaborate explainers on a selected few.

+

Getting a backtrace for errors

+

If you want to get a backtrace to the point where the compiler emits an +error message, you can pass the -Z treat-err-as-bug=n, which will make +the compiler panic on the nth error. If you leave off =n, the compiler will +assume 1 for n and thus panic on the first error it encounters.

+

For example:

+
$ cat error.rs
+
+
fn main() {
+    1 + ();
+}
+
+
$ rustc +stage1 error.rs
+error[E0277]: cannot add `()` to `{integer}`
+ --> error.rs:2:7
+  |
+2 |       1 + ();
+  |         ^ no implementation for `{integer} + ()`
+  |
+  = help: the trait `Add<()>` is not implemented for `{integer}`
+
+error: aborting due to previous error
+
+

Now, where does the error above come from?

+
$ RUST_BACKTRACE=1 rustc +stage1 error.rs -Z treat-err-as-bug
+error[E0277]: the trait bound `{integer}: std::ops::Add<()>` is not satisfied
+ --> error.rs:2:7
+  |
+2 |     1 + ();
+  |       ^ no implementation for `{integer} + ()`
+  |
+  = help: the trait `std::ops::Add<()>` is not implemented for `{integer}`
+
+error: internal compiler error: unexpected panic
+
+note: the compiler unexpectedly panicked. this is a bug.
+
+note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
+
+note: rustc 1.24.0-dev running on x86_64-unknown-linux-gnu
+
+note: run with `RUST_BACKTRACE=1` for a backtrace
+
+thread 'rustc' panicked at 'encountered error with `-Z treat_err_as_bug',
+/home/user/rust/compiler/rustc_errors/src/lib.rs:411:12
+note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose
+backtrace.
+stack backtrace:
+  (~~~ IRRELEVANT PART OF BACKTRACE REMOVED BY ME ~~~)
+   7: rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'tcx>>
+             ::report_selection_error
+             at /home/user/rust/compiler/rustc_middle/src/traits/error_reporting.rs:823
+   8: rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'tcx>>
+             ::report_fulfillment_errors
+             at /home/user/rust/compiler/rustc_middle/src/traits/error_reporting.rs:160
+             at /home/user/rust/compiler/rustc_middle/src/traits/error_reporting.rs:112
+   9: rustc_typeck::check::FnCtxt::select_obligations_where_possible
+             at /home/user/rust/compiler/rustc_typeck/src/check/mod.rs:2192
+  (~~~ IRRELEVANT PART OF BACKTRACE REMOVED BY ME ~~~)
+  36: rustc_driver::run_compiler
+             at /home/user/rust/compiler/rustc_driver/src/lib.rs:253
+
+

Cool, now I have a backtrace for the error!

+

Debugging delayed bugs

+

The -Z eagerly-emit-delayed-bugs option makes it easy to debug delayed bugs. +It turns them into normal errors, i.e. makes them visible. This can be used in +combination with -Z treat-err-as-bug to stop at a particular delayed bug and +get a backtrace.

+

Getting the error creation location

+

-Z track-diagnostics can help figure out where errors are emitted. It uses #[track_caller] +for this and prints its location alongside the error:

+
$ RUST_BACKTRACE=1 rustc +stage1 error.rs -Z track-diagnostics
+error[E0277]: cannot add `()` to `{integer}`
+ --> src\error.rs:2:7
+  |
+2 |     1 + ();
+  |       ^ no implementation for `{integer} + ()`
+-Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs:638:39
+  |
+  = help: the trait `Add<()>` is not implemented for `{integer}`
+  = help: the following other types implement trait `Add<Rhs>`:
+            <&'a f32 as Add<f32>>
+            <&'a f64 as Add<f64>>
+            <&'a i128 as Add<i128>>
+            <&'a i16 as Add<i16>>
+            <&'a i32 as Add<i32>>
+            <&'a i64 as Add<i64>>
+            <&'a i8 as Add<i8>>
+            <&'a isize as Add<isize>>
+          and 48 others
+
+For more information about this error, try `rustc --explain E0277`.
+
+

This is similar but different to -Z treat-err-as-bug:

+
    +
  • it will print the locations for all errors emitted
  • +
  • it does not require a compiler built with debug symbols
  • +
  • you don't have to read through a big stack trace.
  • +
+

Getting logging output

+

The compiler uses the tracing crate for logging.

+

For details see the guide section on tracing

+

Narrowing (Bisecting) Regressions

+

The cargo-bisect-rustc tool can be used as a quick and easy way to +find exactly which PR caused a change in rustc behavior. It automatically +downloads rustc PR artifacts and tests them against a project you provide +until it finds the regression. You can then look at the PR to get more context +on why it was changed. See this tutorial on how to use +it.

+

Downloading Artifacts from Rust's CI

+

The rustup-toolchain-install-master tool by kennytm can be used to +download the artifacts produced by Rust's CI for a specific SHA1 -- this +basically corresponds to the successful landing of some PR -- and then sets +them up for your local use. This also works for artifacts produced by @bors try. This is helpful when you want to examine the resulting build of a PR +without doing the build yourself.

+

#[rustc_*] TEST attributes

+

The compiler defines a whole lot of internal (perma-unstable) attributes some of which are useful +for debugging by dumping extra compiler-internal information. These are prefixed with rustc_ and +are gated behind the internal feature rustc_attrs (enabled via e.g. #![feature(rustc_attrs)]).

+

For a complete and up to date list, see builtin_attrs. More specifically, the ones marked TEST. +Here are some notable ones:

+
+ + + + + + + + + + + + +
AttributeDescription
rustc_def_pathDumps the def_path_str of an item.
rustc_dump_def_parentsDumps the chain of DefId parents of certain definitions.
rustc_dump_item_boundsDumps the item_bounds of an item.
rustc_dump_predicatesDumps the predicates_of an item.
rustc_dump_vtable
rustc_hidden_type_of_opaquesDumps the hidden type of each opaque types in the crate.
rustc_layoutSee this section.
rustc_object_lifetime_defaultDumps the object lifetime defaults of an item.
rustc_outlivesDumps implied bounds of an item. More precisely, the inferred_outlives_of an item.
rustc_regionsDumps NLL closure region requirements.
rustc_symbol_nameDumps the mangled & demangled symbol_name of an item.
rustc_variancesDumps the variances of an item.
+
+

Right below you can find elaborate explainers on a selected few.

+

Formatting Graphviz output (.dot files)

+

Some compiler options for debugging specific features yield graphviz graphs - +e.g. the #[rustc_mir(borrowck_graphviz_postflow="suffix.dot")] attribute +dumps various borrow-checker dataflow graphs.

+

These all produce .dot files. To view these files, install graphviz (e.g. +apt-get install graphviz) and then run the following commands:

+
$ dot -T pdf maybe_init_suffix.dot > maybe_init_suffix.pdf
+$ firefox maybe_init_suffix.pdf # Or your favorite pdf viewer
+
+

Debugging type layouts

+

The internal attribute #[rustc_layout] can be used to dump the Layout of +the type it is attached to. For example:

+
#![allow(unused)]
+#![feature(rustc_attrs)]
+
+fn main() {
+#[rustc_layout(debug)]
+type T<'a> = &'a u32;
+}
+
+

Will emit the following:

+
error: layout_of(&'a u32) = Layout {
+    fields: Primitive,
+    variants: Single {
+        index: 0,
+    },
+    abi: Scalar(
+        Scalar {
+            value: Pointer,
+            valid_range: 1..=18446744073709551615,
+        },
+    ),
+    largest_niche: Some(
+        Niche {
+            offset: Size {
+                raw: 0,
+            },
+            scalar: Scalar {
+                value: Pointer,
+                valid_range: 1..=18446744073709551615,
+            },
+        },
+    ),
+    align: AbiAndPrefAlign {
+        abi: Align {
+            pow2: 3,
+        },
+        pref: Align {
+            pow2: 3,
+        },
+    },
+    size: Size {
+        raw: 8,
+    },
+}
+ --> src/lib.rs:4:1
+  |
+4 | type T<'a> = &'a u32;
+  | ^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+

Configuring CodeLLDB for debugging rustc

+

If you are using VSCode, and have edited your config.toml to request debugging +level 1 or 2 for the parts of the code you're interested in, then you should be +able to use the CodeLLDB extension in VSCode to debug it.

+

Here is a sample launch.json file, being used to run a stage 1 compiler direct +from the directory where it is built (does not have to be "installed"):

+
// .vscode/launch.json
+{
+    "version": "0.2.0",
+    "configurations": [
+      {
+        "type": "lldb",
+        "request": "launch",
+        "name": "Launch",
+        "args": [],  // array of string command-line arguments to pass to compiler
+        "program": "${workspaceFolder}/build/host/stage1/bin/rustc",
+        "windows": {  // applicable if using windows
+            "program": "${workspaceFolder}/build/host/stage1/bin/rustc.exe"
+        },
+        "cwd": "${workspaceFolder}",  // current working directory at program start
+        "stopOnEntry": false,
+        "sourceLanguages": ["rust"]
+      }
+    ]
+  }
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/compiler-src.html b/compiler-src.html new file mode 100644 index 000000000..8b4fa0a67 --- /dev/null +++ b/compiler-src.html @@ -0,0 +1,359 @@ + + + + + + The compiler source code - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

High-level overview of the compiler source

+ +

Now that we have seen what the compiler does, +let's take a look at the structure of the rust-lang/rust repository, +where the rustc source code lives.

+
+

You may find it helpful to read the "Overview of the compiler" +chapter, which introduces how the compiler works, before this one.

+
+

Workspace structure

+

The rust-lang/rust repository consists of a single large cargo workspace +containing the compiler, the standard libraries (core, alloc, std, +proc_macro, etc), and rustdoc, along with the build system and a +bunch of tools and submodules for building a full Rust distribution.

+

The repository consists of three main directories:

+ +

Compiler

+

The compiler is implemented in the various compiler/ crates. +The compiler/ crates all have names starting with rustc_*. These are a +collection of around 50 interdependent crates ranging in size from tiny to +huge. There is also the rustc crate which is the actual binary (i.e. the +main function); it doesn't actually do anything besides calling the +rustc_driver crate, which drives the various parts of compilation in other +crates.

+

The dependency structure of these crates is complex, but roughly it is +something like this:

+
    +
  • rustc (the binary) calls rustc_driver::main. +
      +
    • rustc_driver depends on a lot of other crates, but the main one is +rustc_interface. +
        +
      • rustc_interface depends on most of the other compiler crates. It +is a fairly generic interface for driving the whole compilation. +
          +
        • Most of the other rustc_* crates depend on rustc_middle, +which defines a lot of central data structures in the compiler. + +
        • +
        +
      • +
      +
    • +
    +
  • +
+

You can see the exact dependencies by reading the Cargo.toml for the various +crates, just like a normal Rust crate.

+

One final thing: src/llvm-project is a submodule for our fork of LLVM. +During bootstrapping, LLVM is built and the compiler/rustc_llvm crate +contains Rust wrappers around LLVM (which is written in C++), so that the +compiler can interface with it.

+

Most of this book is about the compiler, so we won't have any further +explanation of these crates here.

+

Big picture

+

The dependency structure of the compiler is influenced by two main factors:

+
    +
  1. Organization. The compiler is a huge codebase; it would be an impossibly +large crate. In part, the dependency structure reflects the code structure +of the compiler.
  2. +
  3. Compile-time. By breaking the compiler into multiple crates, we can take +better advantage of incremental/parallel compilation using cargo. In +particular, we try to have as few dependencies between crates as possible so +that we don't have to rebuild as many crates if you change one.
  4. +
+

At the very bottom of the dependency tree are a handful of crates that are used +by the whole compiler (e.g. rustc_span). The very early parts of the +compilation process (e.g. parsing and the Abstract Syntax Tree (AST)) +depend on only these.

+

After the AST is constructed and other early analysis is done, the +compiler's query system gets set up. The query system is set up in a +clever way using function pointers. This allows us to break dependencies +between crates, allowing more parallel compilation. The query system is defined +in rustc_middle, so nearly all subsequent parts of the compiler depend on +this crate. It is a really large crate, leading to long compile times. Some +efforts have been made to move stuff out of it with varying success. Another +side-effect is that sometimes related functionality gets scattered across +different crates. For example, linting functionality is found across earlier +parts of the crate, rustc_lint, rustc_middle, and other places.

+

Ideally there would be fewer, more cohesive crates, with incremental and +parallel compilation making sure compile times stay reasonable. However, +incremental and parallel compilation haven't gotten good enough for that yet, +so breaking things into separate crates has been our solution so far.

+

At the top of the dependency tree is rustc_driver and rustc_interface +which is an unstable wrapper around the query system helping drive various +stages of compilation. Other consumers of the compiler may use this interface +in different ways (e.g. rustdoc or maybe eventually rust-analyzer). The +rustc_driver crate first parses command line arguments and then uses +rustc_interface to drive the compilation to completion.

+

rustdoc

+

The bulk of rustdoc is in librustdoc. However, the rustdoc binary +itself is src/tools/rustdoc, which does nothing except call rustdoc::main.

+

There is also JavaScript and CSS for the docs in src/tools/rustdoc-js +and src/tools/rustdoc-themes.

+

You can read more about rustdoc in this chapter.

+

Tests

+

The test suite for all of the above is in tests/. You can read more +about the test suite in this chapter.

+

The test harness is in src/tools/compiletest/.

+

Build System

+

There are a number of tools in the repository just for building the compiler, +standard library, rustdoc, etc, along with testing, building a full Rust +distribution, etc.

+

One of the primary tools is src/bootstrap/. You can read more about +bootstrapping in this chapter. The process may also use other tools +from src/tools/, such as tidy/ or compiletest/.

+

Standard library

+

This code is fairly similar to most other Rust crates except that it must be +built in a special way because it can use unstable (nightly) features. +The standard library is sometimes referred to as libstd or the "standard facade".

+

Other

+

There are a lot of other things in the rust-lang/rust repo that are related +to building a full Rust distribution. Most of the time you don't need to worry about them.

+

These include:

+
    +
  • src/ci: The CI configuration. This actually quite extensive because we +run a lot of tests on a lot of platforms.
  • +
  • src/doc: Various documentation, including submodules for a few books.
  • +
  • src/etc: Miscellaneous utilities.
  • +
  • And more...
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/compiler-team.html b/compiler-team.html new file mode 100644 index 000000000..b6eddd510 --- /dev/null +++ b/compiler-team.html @@ -0,0 +1,315 @@ + + + + + + About the compiler team - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

About the compiler team

+

rustc is maintained by the Rust compiler team. The people who belong to +this team collectively work to track regressions and implement new features. +Members of the Rust compiler team are people who have made significant +contributions to rustc and its design.

+

Discussion

+

Currently the compiler team chats in Zulip:

+
    +
  • Team chat occurs in the t-compiler stream on the Zulip instance
  • +
  • There are also a number of other associated Zulip streams, +such as t-compiler/help, where people can ask for help +with rustc development, or t-compiler/meetings, +where the team holds their weekly triage and steering meetings.
  • +
+

Reviewers

+

If you're interested in figuring out who can answer questions about a +particular part of the compiler, or you'd just like to know who works on what, +check out triagebot.toml's assign section. +It contains a listing of the various parts of the compiler and a list of people +who are reviewers of each part.

+

Rust compiler meeting

+

The compiler team has a weekly meeting where we do triage and try to +generally stay on top of new bugs, regressions, and discuss important +things in general. +They are held on Zulip. It works roughly as follows:

+
    +
  • Announcements, MCPs/FCPs, and WG-check-ins: We share some +announcements with the rest of the team about important things we want +everyone to be aware of. We also share the status of MCPs and FCPs and we +use the opportunity to have a couple of WGs giving us an update about +their work.
  • +
  • Check for beta and stable nominations: These are nominations of things to +backport to beta and stable respectively. +We then look for new cases where the compiler broke previously working +code in the wild. Regressions are important issues to fix, so it's +likely that they are tagged as P-critical or P-high; the major +exception would be bug fixes (though even there we often aim to give +warnings first).
  • +
  • Review P-critical and P-high bugs: P-critical and P-high bugs are +those that are sufficiently important for us to actively track +progress. P-critical and P-high bugs should ideally always have an +assignee.
  • +
  • Check S-waiting-on-team and I-nominated issues: These are issues where feedback from +the team is desired.
  • +
  • Look over the performance triage report: We check for PRs that made the +performance worse and try to decide if it's worth reverting the performance regression or if +the regression can be addressed in a future PR.
  • +
+

The meeting currently takes place on Thursdays at 10am Boston time +(UTC-4 typically, but daylight savings time sometimes makes things +complicated).

+

Team membership

+

Membership in the Rust team is typically offered when someone has been +making significant contributions to the compiler for some +time. Membership is both a recognition but also an obligation: +compiler team members are generally expected to help with upkeep as +well as doing reviews and other work.

+

If you are interested in becoming a compiler team member, the first +thing to do is to start fixing some bugs, or get involved in a working +group. One good way to find bugs is to look for +open issues tagged with E-easy +or +E-mentor.

+

You can also dig through the graveyard of PRs that were +closed due to inactivity, +some of them may contain work that is still useful - refer to the +associated issues, if any - and only needs some finishing touches +for which the original author didn't have time.

+

r+ rights

+

Once you have made a number of individual PRs to rustc, we will often +offer r+ privileges. This means that you have the right to instruct +"bors" (the robot that manages which PRs get landed into rustc) to +merge a PR +(here are some instructions for how to talk to bors).

+

The guidelines for reviewers are as follows:

+
    +
  • You are always welcome to review any PR, regardless of who it is +assigned to. However, do not r+ PRs unless: +
      +
    • You are confident in that part of the code.
    • +
    • You are confident that nobody else wants to review it first. +
        +
      • For example, sometimes people will express a desire to review a +PR before it lands, perhaps because it touches a particularly +sensitive part of the code.
      • +
      +
    • +
    +
  • +
  • Always be polite when reviewing: you are a representative of the +Rust project, so it is expected that you will go above and beyond +when it comes to the Code of Conduct.
  • +
+

Reviewer rotation

+

Once you have r+ rights, you can also be added to the reviewer rotation. +triagebot is the bot that automatically assigns incoming PRs to reviewers. +If you are added, you will be randomly selected to review +PRs. If you find you are assigned a PR that you don't feel comfortable +reviewing, you can also leave a comment like r? @so-and-so to assign +to someone else — if you don't know who to request, just write r? @nikomatsakis for reassignment and @nikomatsakis will pick someone +for you.

+

Getting on the reviewer rotation is much appreciated as it lowers the +review burden for all of us! However, if you don't have time to give +people timely feedback on their PRs, it may be better that you don't +get on the list.

+

Full team membership

+

Full team membership is typically extended once someone made many +contributions to the Rust compiler over time, ideally (but not +necessarily) to multiple areas. Sometimes this might be implementing a +new feature, but it is also important — perhaps more important! — to +have time and willingness to help out with general upkeep such as +bugfixes, tracking regressions, and other less glamorous work.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/compiletest.html b/compiletest.html new file mode 100644 index 000000000..b90209360 --- /dev/null +++ b/compiletest.html @@ -0,0 +1,12 @@ + + + + + Redirecting... + + + + +

Redirecting to... tests/compiletest.html.

+ + diff --git a/const-eval.html b/const-eval.html new file mode 100644 index 000000000..5bf3cb0b9 --- /dev/null +++ b/const-eval.html @@ -0,0 +1,253 @@ + + + + + + Constant evaluation - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Constant Evaluation

+

Constant evaluation is the process of computing values at compile time. For a +specific item (constant/static/array length) this happens after the MIR for the +item is borrow-checked and optimized. In many cases trying to const evaluate an +item will trigger the computation of its MIR for the first time.

+

Prominent examples are:

+
    +
  • The initializer of a static
  • +
  • Array length +
      +
    • needs to be known to reserve stack or heap space
    • +
    +
  • +
  • Enum variant discriminants +
      +
    • needs to be known to prevent two variants from having the same +discriminant
    • +
    +
  • +
  • Patterns +
      +
    • need to be known to check for overlapping patterns
    • +
    +
  • +
+

Additionally constant evaluation can be used to reduce the workload or binary +size at runtime by precomputing complex operations at compiletime and only +storing the result.

+

All uses of constant evaluation can either be categorized as "influencing the type system" +(array lengths, enum variant discriminants, const generic parameters), or as solely being +done to precompute expressions to be used at runtime.

+

Constant evaluation can be done by calling the const_eval_* functions of TyCtxt. +They're the wrappers of the const_eval query.

+
    +
  • const_eval_global_id_for_typeck evaluates a constant to a valtree, +so the result value can be further inspected by the compiler.
  • +
  • const_eval_global_id evaluate a constant to an "opaque blob" containing its final value; +this is only useful for codegen backends and the CTFE evaluator engine itself.
  • +
  • eval_static_initializer specifically computes the initial values of a static. +Statics are special; all other functions do not represent statics correctly +and have thus assertions preventing their use on statics.
  • +
+

The const_eval_* functions use a ParamEnv of environment +in which the constant is evaluated (e.g. the function within which the constant is used) +and a GlobalId. The GlobalId is made up of an Instance referring to a constant +or static or of an Instance of a function and an index into the function's Promoted table.

+

Constant evaluation returns an EvalToValTreeResult for type system constants +or EvalToConstValueResult with either the error, or a representation of the +evaluated constant: a valtree or a MIR constant +value, respectively.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/const-eval/interpret.html b/const-eval/interpret.html new file mode 100644 index 000000000..85d9cb9ad --- /dev/null +++ b/const-eval/interpret.html @@ -0,0 +1,396 @@ + + + + + + Interpreter - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Interpreter

+ +

The interpreter is a virtual machine for executing MIR without compiling to +machine code. It is usually invoked via tcx.const_eval_* functions. The +interpreter is shared between the compiler (for compile-time function +evaluation, CTFE) and the tool Miri, which +uses the same virtual machine to detect Undefined Behavior in (unsafe) Rust +code.

+

If you start out with a constant:

+
#![allow(unused)]
+fn main() {
+const FOO: usize = 1 << 12;
+}
+
+

rustc doesn't actually invoke anything until the constant is either used or +placed into metadata.

+

Once you have a use-site like:

+
type Foo = [u8; FOO - 42];
+
+

The compiler needs to figure out the length of the array before being able to +create items that use the type (locals, constants, function arguments, ...).

+

To obtain the (in this case empty) parameter environment, one can call +let param_env = tcx.param_env(length_def_id);. The GlobalId needed is

+
let gid = GlobalId {
+    promoted: None,
+    instance: Instance::mono(length_def_id),
+};
+
+

Invoking tcx.const_eval(param_env.and(gid)) will now trigger the creation of +the MIR of the array length expression. The MIR will look something like this:

+
Foo::{{constant}}#0: usize = {
+    let mut _0: usize;
+    let mut _1: (usize, bool);
+
+    bb0: {
+        _1 = CheckedSub(const FOO, const 42usize);
+        assert(!move (_1.1: bool), "attempt to subtract with overflow") -> bb1;
+    }
+
+    bb1: {
+        _0 = move (_1.0: usize);
+        return;
+    }
+}
+
+

Before the evaluation, a virtual memory location (in this case essentially a +vec![u8; 4] or vec![u8; 8]) is created for storing the evaluation result.

+

At the start of the evaluation, _0 and _1 are +Operand::Immediate(Immediate::Scalar(ScalarMaybeUndef::Undef)). This is quite +a mouthful: Operand can represent either data stored somewhere in the +interpreter memory (Operand::Indirect), or (as an optimization) +immediate data stored in-line. And Immediate can either be a single +(potentially uninitialized) scalar value (integer or thin pointer), +or a pair of two of them. In our case, the single scalar value is not (yet) +initialized.

+

When the initialization of _1 is invoked, the value of the FOO constant is +required, and triggers another call to tcx.const_eval_*, which will not be shown +here. If the evaluation of FOO is successful, 42 will be subtracted from its +value 4096 and the result stored in _1 as +Operand::Immediate(Immediate::ScalarPair(Scalar::Raw { data: 4054, .. }, Scalar::Raw { data: 0, .. }). The first part of the pair is the computed value, +the second part is a bool that's true if an overflow happened. A Scalar::Raw +also stores the size (in bytes) of this scalar value; we are eliding that here.

+

The next statement asserts that said boolean is 0. In case the assertion +fails, its error message is used for reporting a compile-time error.

+

Since it does not fail, Operand::Immediate(Immediate::Scalar(Scalar::Raw { data: 4054, .. })) is stored in the virtual memory it was allocated before the +evaluation. _0 always refers to that location directly.

+

After the evaluation is done, the return value is converted from Operand to +ConstValue by op_to_const: the former representation is geared towards +what is needed during const evaluation, while ConstValue is shaped by the +needs of the remaining parts of the compiler that consume the results of const +evaluation. As part of this conversion, for types with scalar values, even if +the resulting Operand is Indirect, it will return an immediate +ConstValue::Scalar(computed_value) (instead of the usual ConstValue::ByRef). +This makes using the result much more efficient and also more convenient, as no +further queries need to be executed in order to get at something as simple as a +usize.

+

Future evaluations of the same constants will not actually invoke +the interpreter, but just use the cached result.

+

Datastructures

+

The interpreter's outside-facing datastructures can be found in +rustc_middle/src/mir/interpret. +This is mainly the error enum and the ConstValue and Scalar types. A +ConstValue can be either Scalar (a single Scalar, i.e., integer or thin +pointer), Slice (to represent byte slices and strings, as needed for pattern +matching) or ByRef, which is used for anything else and refers to a virtual +allocation. These allocations can be accessed via the methods on +tcx.interpret_interner. A Scalar is either some Raw integer or a pointer; +see the next section for more on that.

+

If you are expecting a numeric result, you can use eval_usize (panics on +anything that can't be represented as a u64) or try_eval_usize which results +in an Option<u64> yielding the Scalar if possible.

+

Memory

+

To support any kind of pointers, the interpreter needs to have a "virtual memory" that the +pointers can point to. This is implemented in the Memory type. In the +simplest model, every global variable, stack variable and every dynamic +allocation corresponds to an Allocation in that memory. (Actually using an +allocation for every MIR stack variable would be very inefficient; that's why we +have Operand::Immediate for stack variables that are both small and never have +their address taken. But that is purely an optimization.)

+

Such an Allocation is basically just a sequence of u8 storing the value of +each byte in this allocation. (Plus some extra data, see below.) Every +Allocation has a globally unique AllocId assigned in Memory. With that, a +Pointer consists of a pair of an AllocId (indicating the allocation) and +an offset into the allocation (indicating which byte of the allocation the +pointer points to). It may seem odd that a Pointer is not just an integer +address, but remember that during const evaluation, we cannot know at which +actual integer address the allocation will end up -- so we use AllocId as +symbolic base addresses, which means we need a separate offset. (As an aside, +it turns out that pointers at run-time are +more than just integers, too.)

+

These allocations exist so that references and raw pointers have something to +point to. There is no global linear heap in which things are allocated, but each +allocation (be it for a local variable, a static or a (future) heap allocation) +gets its own little memory with exactly the required size. So if you have a +pointer to an allocation for a local variable a, there is no possible (no +matter how unsafe) operation that you can do that would ever change said pointer +to a pointer to a different local variable b. +Pointer arithmetic on a will only ever change its offset; the AllocId stays the same.

+

This, however, causes a problem when we want to store a Pointer into an +Allocation: we cannot turn it into a sequence of u8 of the right length! +AllocId and offset together are twice as big as a pointer "seems" to be. This +is what the relocation field of Allocation is for: the byte offset of the +Pointer gets stored as a bunch of u8, while its AllocId gets stored +out-of-band. The two are reassembled when the Pointer is read from memory. +The other bit of extra data an Allocation needs is undef_mask for keeping +track of which of its bytes are initialized.

+

Global memory and exotic allocations

+

Memory exists only during evaluation; it gets destroyed when the +final value of the constant is computed. In case that constant contains any +pointers, those get "interned" and moved to a global "const eval memory" that is +part of TyCtxt. These allocations stay around for the remaining computation +and get serialized into the final output (so that dependent crates can use +them).

+

Moreover, to also support function pointers, the global memory in TyCtxt can +also contain "virtual allocations": instead of an Allocation, these contain an +Instance. That allows a Pointer to point to either normal data or a +function, which is needed to be able to evaluate casts from function pointers to +raw pointers.

+

Finally, the GlobalAlloc type used in the global memory also contains a +variant Static that points to a particular const or static item. This is +needed to support circular statics, where we need to have a Pointer to a +static for which we cannot yet have an Allocation as we do not know the +bytes of its value.

+

Pointer values vs Pointer types

+

One common cause of confusion in the interpreter is that being a pointer value and having +a pointer type are entirely independent properties. By "pointer value", we +refer to a Scalar::Ptr containing a Pointer and thus pointing somewhere into +the interpreter's virtual memory. This is in contrast to Scalar::Raw, which is just some +concrete integer.

+

However, a variable of pointer or reference type, such as *const T or &T, +does not have to have a pointer value: it could be obtained by casting or +transmuting an integer to a pointer. +And similarly, when casting or transmuting a reference to some +actual allocation to an integer, we end up with a pointer value +(Scalar::Ptr) at integer type (usize). This is a problem because we +cannot meaningfully perform integer operations such as division on pointer +values.

+

Interpretation

+

Although the main entry point to constant evaluation is the tcx.const_eval_* +functions, there are additional functions in +rustc_const_eval/src/const_eval +that allow accessing the fields of a ConstValue (ByRef or otherwise). You should +never have to access an Allocation directly except for translating it to the +compilation target (at the moment just LLVM).

+

The interpreter starts by creating a virtual stack frame for the current constant that is +being evaluated. There's essentially no difference between a constant and a +function with no arguments, except that constants do not allow local (named) +variables at the time of writing this guide.

+

A stack frame is defined by the Frame type in +rustc_const_eval/src/interpret/eval_context.rs +and contains all the local +variables memory (None at the start of evaluation). Each frame refers to the +evaluation of either the root constant or subsequent calls to const fn. The +evaluation of another constant simply calls tcx.const_eval_*, which produce an +entirely new and independent stack frame.

+

The frames are just a Vec<Frame>, there's no way to actually refer to a +Frame's memory even if horrible shenanigans are done via unsafe code. The only +memory that can be referred to are Allocations.

+

The interpreter now calls the step method (in +rustc_const_eval/src/interpret/step.rs +) until it either returns an error or has no further statements to execute. Each +statement will now initialize or modify the locals or the virtual memory +referred to by a local. This might require evaluating other constants or +statics, which just recursively invokes tcx.const_eval_*.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/constants.html b/constants.html new file mode 100644 index 000000000..b24a5c106 --- /dev/null +++ b/constants.html @@ -0,0 +1,268 @@ + + + + + + Constants in the type system - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Constants in the type system

+

Constants used in the type system are represented as ty::Const. +The variants of their const_kind::ConstKind mostly mirror the variants of ty_kind::TyKind +with the two additional variants being ConstKind::Value and ConstKind::Unevaluated.

+

WithOptConstParam and dealing with the query system

+

To typecheck constants used in the type system, we have to know their expected type. +For const arguments in type dependent paths, e.g. x.foo::<{ 3 + 4 }>(), we don't know +the expected type for { 3 + 4 } until we are typechecking the containing function.

+

As we may however have to evaluate that constant during this typecheck, we would get a cycle error. +For more details, you can look at this document.

+

Unevaluated constants

+

This section talks about what's happening with feature(generic_const_exprs) enabled. +On stable we do not yet supply any generic parameters to anonymous constants, +avoiding most of the issues mentioned here.

+

Unless a constant is either a simple literal, e.g. [u8; 3] or foo::<{ 'c' }>(), +or a generic parameter, e.g. [u8; N], converting a constant to its ty::Const representation +returns an unevaluated constant. Even fully concrete constants which do not depend on +generic parameters are not evaluated right away.

+

Anonymous constants are typechecked separately from their containing item, e.g.

+
#![allow(unused)]
+fn main() {
+fn foo<const N: usize>() -> [u8; N + 1] {
+    [0; N + 1]
+}
+}
+
+

is treated as

+
#![allow(unused)]
+fn main() {
+const ANON_CONST_1<const N: usize> = N + 1;
+const ANON_CONST_2<const N: usize> = N + 1;
+fn foo<const N: usize>() -> [u8; ANON_CONST_1::<N>] {
+    [0; ANON_CONST_2::<N>]
+}
+}
+
+

Unifying constants

+

For the compiler, ANON_CONST_1 and ANON_CONST_2 are completely different, so +we have to somehow look into unevaluated constants to check whether they should +unify.

+

For this we use InferCtxt::try_unify_abstract_consts. +This builds a custom AST for the two inputs from their THIR. This is then used for +the actual comparison.

+

Lazy normalization for constants

+

We do not eagerly evaluate constant as they can be used in the where-clauses of their +parent item, for example:

+
#![allow(unused)]
+fn main() {
+#[feature(generic_const_exprs)]
+fn foo<T: Trait>()
+where
+    [u8; <T as  Trait>::ASSOC + 1]: SomeOtherTrait,
+{}
+}
+
+

The constant <T as Trait>::ASSOC + 1 depends on the T: Trait bound of +its parents caller bounds, but is also part of another bound itself. +If we were to eagerly evaluate this constant while computing its parents bounds +this would cause a query cycle.

+

Unused generic arguments of anonymous constants

+

Anonymous constants inherit the generic parameters of their parent, which is +why the array length in foo<const N: usize>() -> [u8; N + 1] can use N.

+

Without any manual adjustments, this causes us to include parameters even if +the constant doesn't use them in any way. This can cause +some interesting errors and breaks some already stable code.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/contributing.html b/contributing.html new file mode 100644 index 000000000..a1a964c9a --- /dev/null +++ b/contributing.html @@ -0,0 +1,618 @@ + + + + + + Contribution Procedures - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Contribution Procedures

+ +

Bug reports

+

While bugs are unfortunate, they're a reality in software. We can't fix what we +don't know about, so please report liberally. If you're not sure if something +is a bug or not, feel free to file a bug anyway.

+

If you believe reporting your bug publicly represents a security risk to Rust users, +please follow our instructions for reporting security vulnerabilities.

+

If you're using the nightly channel, please check if the bug exists in the +latest toolchain before filing your bug. It might be fixed already.

+

If you have the chance, before reporting a bug, please search existing issues, +as it's possible that someone else has already reported your error. This doesn't +always work, and sometimes it's hard to know what to search for, so consider this +extra credit. We won't mind if you accidentally file a duplicate report.

+

Similarly, to help others who encountered the bug find your issue, consider +filing an issue with a descriptive title, which contains information that might +be unique to it. This can be the language or compiler feature used, the +conditions that trigger the bug, or part of the error message if there is any. +An example could be: "impossible case reached" on lifetime inference for impl +Trait in return position.

+

Opening an issue is as easy as following this +link and filling out the fields +in the appropriate provided template.

+

Bug fixes or "normal" code changes

+

For most PRs, no special procedures are needed. You can just open a PR, and it +will be reviewed, approved, and merged. This includes most bug fixes, +refactorings, and other user-invisible changes. The next few sections talk +about exceptions to this rule.

+

Also, note that it is perfectly acceptable to open WIP PRs or GitHub Draft PRs. +Some people prefer to do this so they can get feedback along the +way or share their code with a collaborator. Others do this so they can utilize +the CI to build and test their PR (e.g. when developing on a slow machine).

+

New features

+

Rust has strong backwards-compatibility guarantees. Thus, new features can't +just be implemented directly in stable Rust. Instead, we have 3 release +channels: stable, beta, and nightly.

+
    +
  • Stable: this is the latest stable release for general usage.
  • +
  • Beta: this is the next release (will be stable within 6 weeks).
  • +
  • Nightly: follows the master branch of the repo. This is the only +channel where unstable, incomplete, or experimental features are usable with +feature gates.
  • +
+

See this chapter on implementing new features for more +information.

+

Breaking changes

+

Breaking changes have a dedicated section in the dev-guide.

+

Major changes

+

The compiler team has a special process for large changes, whether or not they +cause breakage. This process is called a Major Change Proposal (MCP). MCP is a +relatively lightweight mechanism for getting feedback on large changes to the +compiler (as opposed to a full RFC or a design meeting with the team).

+

Example of things that might require MCPs include major refactorings, changes +to important types, or important changes to how the compiler does something, or +smaller user-facing changes.

+

When in doubt, ask on zulip. It would be a shame to put a lot of work +into a PR that ends up not getting merged! See this document for +more info on MCPs.

+

Performance

+

Compiler performance is important. We have put a lot of effort over the last +few years into gradually improving it.

+

If you suspect that your change may cause a performance regression (or +improvement), you can request a "perf run" (and your reviewer may also request one +before approving). This is yet another bot that will compile a collection of +benchmarks on a compiler with your changes. The numbers are reported +here, and you can see a comparison of your changes against the latest +master.

+
+

For an introduction to the performance of Rust code in general +which would also be useful in rustc development, see The Rust Performance Book.

+
+

Pull requests

+

Pull requests (or PRs for short) are the primary mechanism we use to change Rust. +GitHub itself has some great documentation on using the +Pull Request feature. We use the "fork and pull" model described here, +where contributors push changes to their personal fork and create pull requests to +bring those changes into the source repository. We have more info about how to use git +when contributing to Rust under the git section.

+
+

Advice for potentially large, complex, cross-cutting and/or very domain-specific changes

+

The compiler reviewers on rotation usually each have areas of the compiler that they know well, +but also have areas that they are not very familiar with. If your PR contains changes that are +large, complex, cross-cutting and/or highly domain-specific, it becomes very difficult to find a +suitable reviewer who is comfortable in reviewing all of the changes in such a PR. This is also +true if the changes are not only compiler-specific but also contains changes which fall under the +purview of reviewers from other teams, like the standard library team. There's a bot +which notifies the relevant teams and pings people who have setup specific alerts based on the +files modified.

+

Before making such changes, you are strongly encouraged to discuss your proposed changes with +the compiler team beforehand (and with other teams that the changes would require approval +from), and work with the compiler team to see if we can help you break down a large potentially +unreviewable PR into a series of smaller more individually reviewable PRs.

+

You can communicate with the compiler team by creating a #t-compiler thread on zulip +to discuss your proposed changes.

+

Communicating with the compiler team beforehand helps in several ways:

+
    +
  1. It increases the likelihood of your PRs being reviewed in a timely manner. +
      +
    • We can help you identify suitable reviewers before you open actual PRs, or help find +advisors and liaisons to help you navigate the change procedures, or help with running +try-jobs, perf runs and crater runs as suitable.
    • +
    +
  2. +
  3. It helps the compiler team track your changes.
  4. +
  5. The compiler team can perform vibe checks on your changes early and often, to see if the +direction of the changes align with what the compiler team prefers to see.
  6. +
  7. Helps to avoid situations where you may have invested significant time and effort into large +changes that the compiler team might not be willing to accept, or finding out very late that the +changes are in a direction that the compiler team disagrees with.
  8. +
+
+

r?

+

All pull requests are reviewed by another person. We have a bot, +@rustbot, that will automatically assign a random person +to review your request based on which files you changed.

+

If you want to request that a specific person reviews your pull request, you +can add an r? to the pull request description or in a comment. For example, +if you want to ask a review to @awesome-reviewer, add

+
r? @awesome-reviewer
+
+

to the end of the pull request description, and @rustbot will assign +them instead of a random person. This is entirely optional.

+

You can also assign a random reviewer from a specific team by writing r? rust-lang/groupname. +As an example, +if you were making a diagnostics change, +then you could get a reviewer from the diagnostics team by adding:

+
r? rust-lang/diagnostics
+
+

For a full list of possible groupnames, +check the adhoc_groups section at the triagebot.toml config file, +or the list of teams in the rust-lang teams database.

+

Waiting for reviews

+
+

NOTE

+

Pull request reviewers are often working at capacity, +and many of them are contributing on a volunteer basis. +In order to minimize review delays, +pull request authors and assigned reviewers should ensure that the review label +(S-waiting-on-review and S-waiting-on-author) stays updated, +invoking these commands when appropriate:

+
    +
  • +

    @rustbot author: +the review is finished, +and PR author should check the comments and take action accordingly.

    +
  • +
  • +

    @rustbot review: +the author is ready for a review, +and this PR will be queued again in the reviewer's queue.

    +
  • +
+
+

Please note that the reviewers are humans, who for the most part work on rustc +in their free time. This means that they can take some time to respond and review +your PR. It also means that reviewers can miss some PRs that are assigned to them.

+

To try to move PRs forward, the Triage WG regularly goes through all PRs that +are waiting for review and haven't been discussed for at least 2 weeks. If you +don't get a review within 2 weeks, feel free to ask the Triage WG on +Zulip (#t-release/triage). They have knowledge of when to ping, who might be +on vacation, etc.

+

The reviewer may request some changes using the GitHub code review interface. +They may also request special procedures for some PRs. +See Crater and Breaking Changes chapters for some examples of such procedures.

+

CI

+

In addition to being reviewed by a human, pull requests are automatically tested, +thanks to continuous integration (CI). Basically, every time you open and update +a pull request, CI builds the compiler and tests it against the +compiler test suite, and also performs other tests such as checking that +your pull request is in compliance with Rust's style guidelines.

+

Running continuous integration tests allows PR authors to catch mistakes early +without going through a first review cycle, and also helps reviewers stay aware +of the status of a particular pull request.

+

Rust has plenty of CI capacity, and you should never have to worry about wasting +computational resources each time you push a change. It is also perfectly fine +(and even encouraged!) to use the CI to test your changes if it can help your +productivity. In particular, we don't recommend running the full ./x test suite locally, +since it takes a very long time to execute.

+

r+

+

After someone has reviewed your pull request, they will leave an annotation +on the pull request with an r+. It will look something like this:

+
@bors r+
+
+

This tells @bors, our lovable integration bot, that your pull request has +been approved. The PR then enters the merge queue, where @bors +will run all the tests on every platform we support. If it all works out, +@bors will merge your code into master and close the pull request.

+

Depending on the scale of the change, you may see a slightly different form of r+:

+
@bors r+ rollup
+
+

The additional rollup tells @bors that this change should always be "rolled up". +Changes that are rolled up are tested and merged alongside other PRs, to +speed the process up. Typically only small changes that are expected not to conflict +with one another are marked as "always roll up".

+

Be patient; this can take a while and the queue can sometimes be long. PRs are never merged by hand.

+

Opening a PR

+

You are now ready to file a pull request? Great! Here are a few points you +should be aware of.

+

All pull requests should be filed against the master branch, +unless you know for sure that you should target a different branch.

+

Make sure your pull request is in compliance with Rust's style guidelines by running

+
$ ./x test tidy --bless
+
+

We recommend to make this check before every pull request (and every new commit +in a pull request); you can add git hooks +before every push to make sure you never forget to make this check. +The CI will also run tidy and will fail if tidy fails.

+

Rust follows a no merge-commit policy, meaning, when you encounter merge +conflicts you are expected to always rebase instead of merging. E.g. always use +rebase when bringing the latest changes from the master branch to your feature +branch. If your PR contains merge commits, it will get marked as has-merge-commits. +Once you have removed the merge commits, e.g., through an interactive rebase, you +should remove the label again:

+
@rustbot label -has-merge-commits
+
+

See this chapter for more details.

+

If you encounter merge conflicts or when a reviewer asks you to perform some +changes, your PR will get marked as S-waiting-on-author. When you resolve +them, you should use @rustbot to mark it as S-waiting-on-review:

+
@rustbot ready
+
+

GitHub allows closing issues using keywords. This feature +should be used to keep the issue tracker tidy. However, it is generally preferred +to put the "closes #123" text in the PR description rather than the issue commit; +particularly during rebasing, citing the issue number in the commit can "spam" +the issue in question.

+

However, if your PR fixes a stable-to-beta or stable-to-stable regression and has +been accepted for a beta and/or stable backport (i.e., it is marked beta-accepted +and/or stable-accepted), please do not use any such keywords since we don't +want the corresponding issue to get auto-closed once the fix lands on master. +Please update the PR description while still mentioning the issue somewhere. +For example, you could write Fixes (after beta backport) #NNN..

+

As for further actions, please keep a sharp look-out for a PR whose title begins with +[beta] or [stable] and which backports the PR in question. When that one gets +merged, the relevant issue can be closed. The closing comment should mention all +PRs that were involved. If you don't have the permissions to close the issue, please +leave a comment on the original PR asking the reviewer to close it for you.

+

Reverting a PR

+

When a PR leads to miscompile, significant performance regressions, or other critical issues, we may +want to revert that PR with a regression test case. You can also check out the revert policy on +Forge docs (which is mainly targeted for reviewers, but contains useful info for PR authors too).

+

If the PR contains huge changes, it can be challenging to revert, making it harder to review +incremental fixes in subsequent updates. Or if certain code in that PR is heavily depended upon by +subsequent PRs, reverting it can become difficult.

+

In such cases, we can identify the problematic code and disable it for some input, as shown in #128271.

+

For MIR optimizations, we can also use the -Zunsound-mir-opt option to gate the mir-opt, as shown +in #132356.

+

External dependencies

+

This section has moved to "Using External Repositories".

+

Writing documentation

+

Documentation improvements are very welcome. The source of doc.rust-lang.org +is located in src/doc in the tree, and standard API documentation is generated +from the source code itself (e.g. library/std/src/lib.rs). Documentation pull requests +function in the same way as other pull requests.

+

To find documentation-related issues, sort by the A-docs label.

+

You can find documentation style guidelines in RFC 1574.

+

To build the standard library documentation, use x doc --stage 0 library --open. +To build the documentation for a book (e.g. the unstable book), use x doc src/doc/unstable-book. +Results should appear in build/host/doc, as well as automatically open in your default browser. +See Building Documentation for more +information.

+

You can also use rustdoc directly to check small fixes. For example, +rustdoc src/doc/reference.md will render reference to doc/reference.html. +The CSS might be messed up, but you can verify that the HTML is right.

+

Contributing to rustc-dev-guide

+

Contributions to the rustc-dev-guide are always welcome, and can be made directly at +the rust-lang/rustc-dev-guide repo. +The issue tracker in that repo is also a great way to find things that need doing. +There are issues for beginners and advanced compiler devs alike!

+

Just a few things to keep in mind:

+
    +
  • +

    Please try to avoid overly long lines and use semantic line breaks (where you break the line after each sentence). +There is no strict limit on line lengths; let the sentence or part of the sentence flow to its proper end on the same line.

    +
  • +
  • +

    When contributing text to the guide, please contextualize the information with some time period +and/or a reason so that the reader knows how much to trust or mistrust the information. +Aim to provide a reasonable amount of context, possibly including but not limited to:

    +
      +
    • +

      A reason for why the data may be out of date other than "change", +as change is a constant across the project.

      +
    • +
    • +

      The date the comment was added, e.g. instead of writing "Currently, ..." +or "As of now, ...", +consider adding the date, in one of the following formats:

      +
        +
      • Jan 2021
      • +
      • January 2021
      • +
      • jan 2021
      • +
      • january 2021
      • +
      +

      There is a CI action (in ~/.github/workflows/date-check.yml) +that generates a monthly showing those that are over 6 months old +(example).

      +

      For the action to pick the date, +add a special annotation before specifying the date:

      +
      <!-- date-check --> Sep 2024
      +
      +

      Example:

      +
      As of <!-- date-check --> Sep 2024, the foo did the bar.
      +
      +

      For cases where the date should not be part of the visible rendered output, +use the following instead:

      +
      <!-- date-check: Sep 2024 -->
      +
      +
    • +
    • +

      A link to a relevant WG, tracking issue, rustc rustdoc page, or similar, that may provide +further explanation for the change process or a way to verify that the information is not +outdated.

      +
    • +
    +
  • +
  • +

    If a text grows rather long (more than a few page scrolls) or complicated (more than four +subsections), +it might benefit from having a Table of Contents at the beginning, +which you can auto-generate by including the <!-- toc --> marker at the top.

    +
  • +
+

Issue triage

+

Sometimes, an issue will stay open, even though the bug has been fixed. +And sometimes, the original bug may go stale because something has changed in the meantime.

+

It can be helpful to go through older bug reports and make sure that they are still valid. +Load up an older issue, double check that it's still true, +and leave a comment letting us know if it is or is not. +The least recently updated sort is good for finding issues like this.

+

Thanks to @rustbot, anyone can help triage issues by adding +appropriate labels to issues that haven't been triaged yet:

+ +
+ + + + + + + + + + + + + + + + + + + + + +
LabelsColorDescription
A- YellowThe area of the project an issue relates to.
B- MagentaIssues which are blockers.
beta- Dark BlueTracks changes which need to be backported to beta
C- Light PurpleThe category of an issue.
D- Mossy GreenIssues for diagnostics.
E- GreenThe experience level necessary to fix an issue.
F- PeachIssues for nightly features.
I- RedThe importance of the issue.
I-*-nominated RedThe issue has been nominated for discussion at the next meeting of the corresponding team.
I-prioritize RedThe issue has been nominated for prioritization by the team tagged with a T-prefixed label.
L- TealThe relevant lint.
metabug PurpleBugs that collect other bugs.
O- Purple GreyThe operating system or platform that the issue is specific to.
P- OrangeThe issue priority. These labels can be assigned by anyone that understand the issue and is able to prioritize it, and remove the I-prioritize label.
regression- PinkTracks regressions from a stable release.
relnotes Light OrangeChanges that should be documented in the release notes of the next release.
S- GrayTracks the status of pull requests.
S-tracking- Steel BlueTracks the status of tracking issues.
stable- Dark BlueTracks changes which need to be backported to stable in anticipation of a point release.
T- BlueDenotes which team the issue belongs to.
WG- GreenDenotes which working group the issue belongs to.
+
+

Rfcbot labels

+

rfcbot uses its own labels for tracking the process of coordinating +asynchronous decisions, such as approving or rejecting a change. +This is used for RFCs, issues, and pull requests.

+
+ + + + + + + + + +
LabelsColorDescription
proposed-final-comment-period GrayCurrently awaiting signoff of all team members in order to enter the final comment period.
disposition-merge GreenIndicates the intent is to merge the change.
disposition-close RedIndicates the intent is to not accept the change and close it.
disposition-postpone GrayIndicates the intent is to not accept the change at this time and postpone it to a later date.
final-comment-period BlueCurrently soliciting final comments before merging or closing.
finished-final-comment-period Light YellowThe final comment period has concluded, and the issue will be merged or closed.
postponed YellowThe issue has been postponed.
closed RedThe issue has been rejected.
to-announce GrayIssues that have finished their final-comment-period and should be publicly announced. Note: the rust-lang/rust repository uses this label differently, to announce issues at the triage meetings.
+
+ +

This section has moved to the "About this guide" chapter.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/conventions.html b/conventions.html new file mode 100644 index 000000000..cbf6465d9 --- /dev/null +++ b/conventions.html @@ -0,0 +1,323 @@ + + + + + + Coding conventions - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

This file offers some tips on the coding conventions for rustc. This +chapter covers formatting, coding for correctness, +using crates from crates.io, and some tips on +structuring your PR for easy review.

+

+

Formatting and the tidy script

+

rustc is moving towards the Rust standard coding style.

+

However, for now we don't use stable rustfmt; we use a pinned version with a +special config, so this may result in different style from normal rustfmt. +Therefore, formatting this repository using cargo fmt is not recommended.

+

Instead, formatting should be done using ./x fmt. It's a good habit to run +./x fmt before every commit, as this reduces conflicts later.

+

Formatting is checked by the tidy script. It runs automatically when you do +./x test and can be run in isolation with ./x fmt --check.

+

If you want to use format-on-save in your editor, the pinned version of +rustfmt is built under build/<target>/stage0/bin/rustfmt. You'll have to +pass the --edition=2021 argument yourself when calling +rustfmt directly.

+

Formatting C++ code

+

The compiler contains some C++ code for interfacing with parts of LLVM that +don't have a stable C API. +When modifying that code, use this command to format it:

+
./x test tidy --extra-checks=cpp:fmt --bless
+
+

This uses a pinned version of clang-format, to avoid relying on the local +environment.

+

+ + + + +

In the past, files began with a copyright and license notice. Please omit +this notice for new files licensed under the standard terms (dual +MIT/Apache-2.0).

+

All of the copyright notices should be gone by now, but if you come across one +in the rust-lang/rust repo, feel free to open a PR to remove it.

+

Line length

+

Lines should be at most 100 characters. It's even better if you can +keep things to 80.

+

Ignoring the line length limit. Sometimes – in particular for +tests – it can be necessary to exempt yourself from this limit. In +that case, you can add a comment towards the top of the file like so:

+
#![allow(unused)]
+fn main() {
+// ignore-tidy-linelength
+}
+
+

Tabs vs spaces

+

Prefer 4-space indent.

+

+

Coding for correctness

+

Beyond formatting, there are a few other tips that are worth +following.

+

Prefer exhaustive matches

+

Using _ in a match is convenient, but it means that when new +variants are added to the enum, they may not get handled correctly. +Ask yourself: if a new variant were added to this enum, what's the +chance that it would want to use the _ code, versus having some +other treatment? Unless the answer is "low", then prefer an +exhaustive match. (The same advice applies to if let and while let, which are effectively tests for a single variant.)

+

Use "TODO" comments for things you don't want to forget

+

As a useful tool to yourself, you can insert a // TODO comment +for something that you want to get back to before you land your PR:

+
fn do_something() {
+    if something_else {
+        unimplemented!(); // TODO write this
+    }
+}
+
+

The tidy script will report an error for a // TODO comment, so this +code would not be able to land until the TODO is fixed (or removed).

+

This can also be useful in a PR as a way to signal from one commit that you are +leaving a bug that a later commit will fix:

+
if foo {
+    return true; // TODO wrong, but will be fixed in a later commit
+}
+
+

+

Using crates from crates.io

+

See the crates.io dependencies section.

+

+

How to structure your PR

+

How you prepare the commits in your PR can make a big difference for the +reviewer. Here are some tips.

+

Isolate "pure refactorings" into their own commit. For example, if +you rename a method, then put that rename into its own commit, along +with the renames of all the uses.

+

More commits is usually better. If you are doing a large change, +it's almost always better to break it up into smaller steps that can +be independently understood. The one thing to be aware of is that if +you introduce some code following one strategy, then change it +dramatically (versus adding to it) in a later commit, that +'back-and-forth' can be confusing.

+

Format liberally. While only the final commit of a PR must be correctly +formatted, it is both easier to review and less noisy to format each commit +individually using ./x fmt.

+

No merges. We do not allow merge commits into our history, other +than those by bors. If you get a merge conflict, rebase instead via a +command like git rebase -i rust-lang/master (presuming you use the +name rust-lang for your remote).

+

Individual commits do not have to build (but it's nice). We do not +require that every intermediate commit successfully builds – we only +expect to be able to bisect at a PR level. However, if you can make +individual commits build, that is always helpful.

+

Naming conventions

+

Apart from normal Rust style/naming conventions, there are also some specific +to the compiler.

+
    +
  • +

    cx tends to be short for "context" and is often used as a suffix. For +example, tcx is a common name for the Typing Context.

    +
  • +
  • +

    'tcx is used as the lifetime name for the Typing Context.

    +
  • +
  • +

    Because crate is a keyword, if you need a variable to represent something +crate-related, often the spelling is changed to krate.

    +
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/coroutine-closures.html b/coroutine-closures.html new file mode 100644 index 000000000..d858b9493 --- /dev/null +++ b/coroutine-closures.html @@ -0,0 +1,468 @@ + + + + + + Async closures/"coroutine-closures" - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Please read RFC 3668 to understand the general motivation of the feature. This is a very technical and somewhat "vertical" chapter; ideally we'd split this and sprinkle it across all the relevant chapters, but for the purposes of understanding async closures holistically, I've put this together all here in one chapter.

+

Coroutine-closures -- a technical deep dive

+

Coroutine-closures are a generalization of async closures, being special syntax for closure expressions which return a coroutine, notably one that is allowed to capture from the closure's upvars.

+

For now, the only usable kind of coroutine-closure is the async closure, and supporting async closures is the extent of this PR. We may eventually support gen || {}, etc., and most of the problems and curiosities described in this document apply to all coroutine-closures in general.

+

As a consequence of the code being somewhat general, this document may flip between calling them "async closures" and "coroutine-closures". The future that is returned by the async closure will generally be called the "coroutine" or the "child coroutine".

+

HIR

+

Async closures (and in the future, other coroutine flavors such as gen) are represented in HIR as a hir::Closure whose closure-kind is ClosureKind::CoroutineClosure(_)1, which wraps an async block, which is also represented in HIR as a hir::Closure) and whose closure-kind is ClosureKind::Closure(CoroutineKind::Desugared(_, CoroutineSource::Closure))2.

+ + +

Like async fn, when lowering an async closure's body, we need to unconditionally move all of the closures arguments into the body so they are captured. This is handled by lower_coroutine_body_with_moved_arguments3. The only notable quirk with this function is that the async block we end up generating as a capture kind of CaptureBy::ByRef4. We later force all of the closure args to be captured by-value5, but we don't want the whole async block to act as if it were an async move, since that would defeat the purpose of the self-borrowing of an async closure.

+ + + +

rustc_middle::ty Representation

+

For the purposes of keeping the implementation mostly future-compatible (i.e. with gen || {} and async gen || {}), most of this section calls async closures "coroutine-closures".

+

The main thing that this PR introduces is a new TyKind called CoroutineClosure6 and corresponding variants on other relevant enums in typeck and borrowck (UpvarArgs, DefiningTy, AggregateKind).

+ +

We introduce a new TyKind instead of generalizing the existing TyKind::Closure due to major representational differences in the type. The major differences between CoroutineClosures can be explored by first inspecting the CoroutineClosureArgsParts, which is the "unpacked" representation of the coroutine-closure's generics.

+

Similarities to closures

+

Like a closure, we have parent_args, a closure_kind_ty, and a tupled_upvars_ty. These represent the same thing as their closure counterparts; namely: the generics inherited from the body that the closure is defined in, the maximum "calling capability" of the closure (i.e. must it be consumed to be called, like FnOnce, or can it be called by-ref), and the captured upvars of the closure itself.

+

The signature

+

A traditional closure has a fn_sig_as_fn_ptr_ty which it uses to represent the signature of the closure. In contrast, we store the signature of a coroutine closure in a somewhat "exploded" way, since coroutine-closures have two signatures depending on what AsyncFn* trait you call it with (see below sections).

+

Conceptually, the coroutine-closure may be thought as containing several different signature types depending on whether it is being called by-ref or by-move.

+

To conveniently recreate both of these signatures, the signature_parts_ty stores all of the relevant parts of the coroutine returned by this coroutine-closure. This signature parts type will have the general shape of fn(tupled_inputs, resume_ty) -> (return_ty, yield_ty), where resume_ty, return_ty, and yield_ty are the respective types for the coroutine returned by the coroutine-closure7.

+ +

The compiler mainly deals with the CoroutineClosureSignature type8, which is created by extracting the relevant types out of the fn() ptr type described above, and which exposes methods that can be used to construct the coroutine that the coroutine-closure ultimately returns.

+ +

The data we need to carry along to construct a Coroutine return type

+

Along with the data stored in the signature, to construct a TyKind::Coroutine to return, we also need to store the "witness" of the coroutine.

+

So what about the upvars of the Coroutine that is returned? Well, for AsyncFnOnce (i.e. call-by-move), this is simply the same upvars that the coroutine returns. But for AsyncFnMut/AsyncFn, the coroutine that is returned from the coroutine-closure borrows data from the coroutine-closure with a given "environment" lifetime9. This corresponds to the &self lifetime10 on the AsyncFnMut/AsyncFn call signature, and the GAT lifetime of the ByRef11.

+ + + +

Actually getting the coroutine return type(s)

+

To most easily construct the Coroutine that a coroutine-closure returns, you can use the to_coroutine_given_kind_and_upvars12 helper on CoroutineClosureSignature, which can be acquired from the CoroutineClosureArgs.

+ +

Most of the args to that function will be components that you can get out of the CoroutineArgs, except for the goal_kind: ClosureKind which controls which flavor of coroutine to return based off of the ClosureKind passed in -- i.e. it will prepare the by-ref coroutine if ClosureKind::Fn | ClosureKind::FnMut, and the by-move coroutine if ClosureKind::FnOnce.

+

Trait Hierarchy

+

We introduce a parallel hierarchy of Fn* traits that are implemented for . The motivation for the introduction was covered in a blog post: Async Closures.

+

All currently-stable callable types (i.e., closures, function items, function pointers, and dyn Fn* trait objects) automatically implement AsyncFn*() -> T if they implement Fn*() -> Fut for some output type Fut, and Fut implements Future<Output = T>13.

+ +

Async closures implement AsyncFn* as their bodies permit; i.e. if they end up using upvars in a way that is compatible (i.e. if they consume or mutate their upvars, it may affect whether they implement AsyncFn and AsyncFnMut...)

+

Lending

+

We may in the future move AsyncFn* onto a more general set of LendingFn* traits; however, there are some concrete technical implementation details that limit our ability to use LendingFn ergonomically in the compiler today. These have to do with:

+
    +
  • Closure signature inference.
  • +
  • Limitations around higher-ranked trait bounds.
  • +
  • Shortcomings with error messages.
  • +
+

These limitations, plus the fact that the underlying trait should have no effect on the user experience of async closures and async Fn trait bounds, leads us to AsyncFn* for now. To ensure we can eventually move to these more general traits, the precise AsyncFn* trait definitions (including the associated types) are left as an implementation detail.

+

When do async closures implement the regular Fn* traits?

+

We mention above that "regular" callable types can implement AsyncFn*, but the reverse question exists of "can async closures implement Fn* too"? The short answer is "when it's valid", i.e. when the coroutine that would have been returned from AsyncFn/AsyncFnMut does not actually have any upvars that are "lent" from the parent coroutine-closure.

+

See the "follow-up: when do..." section below for an elaborated answer. The full answer describes a pretty interesting and hopefully thorough heuristic that is used to ensure that most async closures "just work".

+

Tale of two bodies...

+

When async closures are called with AsyncFn/AsyncFnMut, they return a coroutine that borrows from the closure. However, when they are called via AsyncFnOnce, we consume that closure, and cannot return a coroutine that borrows from data that is now dropped.

+

To work around around this limitation, we synthesize a separate by-move MIR body for calling AsyncFnOnce::call_once on a coroutine-closure that can be called by-ref.

+

This body operates identically to the "normal" coroutine returned from calling the coroutine-closure, except for the fact that it has a different set of upvars, since we must move the captures from the parent coroutine-closure into the child coroutine.

+

Synthesizing the by-move body

+

When we want to access the by-move body of the coroutine returned by a coroutine-closure, we can do so via the coroutine_by_move_body_def_id14 query.

+ +

This query synthesizes a new MIR body by copying the MIR body of the coroutine and inserting additional derefs and field projections15 to preserve the semantics of the body.

+ +

Since we've synthesized a new def id, this query is also responsible for feeding a ton of other relevant queries for the MIR body. This query is ensure()d16 during the mir_promoted query, since it operates on the built mir of the coroutine.

+ +

Closure signature inference

+

The closure signature inference algorithm for async closures is a bit more complicated than the inference algorithm for "traditional" closures. Like closures, we iterate through all of the clauses that may be relevant (for the expectation type passed in)17.

+

To extract a signature, we consider two situations:

+
    +
  • Projection predicates with AsyncFnOnce::Output, which we will use to extract the inputs and output type for the closure. This corresponds to the situation that there was a F: AsyncFn*() -> T bound18.
  • +
  • Projection predicates with FnOnce::Output, which we will use to extract the inputs. For the output, we also try to deduce an output by looking for relevant Future::Output projection predicates. This corresponds to the situation that there was an F: Fn*() -> T, T: Future<Output = U> bound.19 +
      +
    • If there is no Future bound, we simply use a fresh infer var for the output. This corresponds to the case where one can pass an async closure to a combinator function like Option::map.20
    • +
    +
  • +
+ + + + +

We support the latter case simply to make it easier for users to simply drop-in async || {} syntax, even when they're calling an API that was designed before first-class AsyncFn* traits were available.

+

Calling a closure before its kind has been inferred

+

We defer21 the computation of a coroutine-closure's "kind" (i.e. its maximum calling mode: AsyncFnOnce/AsyncFnMut/AsyncFn) until the end of typeck. However, since we want to be able to call that coroutine-closure before the end of typeck, we need to come up with the return type of the coroutine-closure before that.

+ +

Unlike regular closures, whose return type does not change depending on what Fn* trait we call it with, coroutine-closures do end up returning different coroutine types depending on the flavor of AsyncFn* trait used to call it.

+

Specifically, while the def-id of the returned coroutine does not change, the upvars22 (which are either borrowed or moved from the parent coroutine-closure) and the coroutine-kind23 are dependent on the calling mode.

+ + +

We introduce a AsyncFnKindHelper trait which allows us to defer the question of "does this coroutine-closure support this calling mode"24 via a trait goal, and "what are the tupled upvars of this calling mode"25 via an associated type, which can be computed by appending the input types of the coroutine-closure to either the upvars or the "by ref" upvars computed during upvar analysis.

+ + +

Ok, so why?

+

This seems a bit roundabout and complex, and I admit that it is. But let's think of the "do nothing" alternative -- we could instead mark all AsyncFn* goals as ambiguous until upvar analysis, at which point we would know exactly what to put into the upvars of the coroutine we return. However, this is actually very detrimental to inference in the program, since it means that programs like this would not be valid:

+
#![allow(unused)]
+fn main() {
+let c = async || -> String { .. };
+let s = c().await;
+// ^^^ If we can't project `<{c} as AsyncFn>::call()` to a coroutine, then the `IntoFuture::into_future` call inside of the `.await` stalls, and the type of `s` is left unconstrained as an infer var.
+s.as_bytes();
+// ^^^ That means we can't call any methods on the awaited return of a coroutine-closure, like... at all!
+}
+
+

So instead, we use this alias (in this case, a projection: AsyncFnKindHelper::Upvars<'env, ...>) to delay the computation of the tupled upvars and give us something to put in its place, while still allowing us to return a TyKind::Coroutine (which is a rigid type) and we may successfully confirm the built-in traits we need (in our case, Future), since the Future implementation doesn't depend on the upvars at all.

+

Upvar analysis

+

By and large, the upvar analysis for coroutine-closures and their child coroutines proceeds like normal upvar analysis. However, there are several interesting bits that happen to account for async closures' special natures:

+

Forcing all inputs to be captured

+

Like async fn, all input arguments are captured. We explicitly force26 all of these inputs to be captured by move so that the future coroutine returned by async closures does not depend on whether the input is used by the body or not, which would impart an interesting semver hazard.

+ +

Computing the by-ref captures

+

For a coroutine-closure that supports AsyncFn/AsyncFnMut, we must also compute the relationship between the captures of the coroutine-closure and its child coroutine. Specifically, the coroutine-closure may move a upvar into its captures, but the coroutine may only borrow that upvar.

+

We compute the "coroutine_captures_by_ref_ty" by looking at all of the child coroutine's captures and comparing them to the corresponding capture of the parent coroutine-closure27. This coroutine_captures_by_ref_ty ends up being represented as a for<'env> fn() -> captures... type, with the additional binder lifetime representing the "&self" lifetime of calling AsyncFn::async_call or AsyncFnMut::async_call_mut. We instantiate that binder later when actually calling the methods.

+ +

Note that not every by-ref capture from the parent coroutine-closure results in a "lending" borrow. See the Follow-up: When do async closures implement the regular Fn* traits? section below for more details, since this intimately influences whether or not the coroutine-closure is allowed to implement the Fn* family of traits.

+

By-move body + FnOnce quirk

+

There are several situations where the closure upvar analysis ends up inferring upvars for the coroutine-closure's child coroutine that are too relaxed, and end up resulting in borrow-checker errors. This is best illustrated via examples. For example, given:

+
#![allow(unused)]
+fn main() {
+fn force_fnonce<T: async FnOnce()>(t: T) -> T { t }
+
+let x = String::new();
+let c = force_fnonce(async move || {
+    println!("{x}");
+});
+}
+
+

x will be moved into the coroutine-closure, but the coroutine that is returned would only borrow &x. However, since force_fnonce forces the coroutine-closure to AsyncFnOnce, which is not lending, we must force the capture to happen by-move28.

+

Similarly:

+
#![allow(unused)]
+fn main() {
+let x = String::new();
+let y = String::new();
+let c = async move || {
+    drop(y);
+    println!("{x}");
+};
+}
+
+

x will be moved into the coroutine-closure, but the coroutine that is returned would only borrow &x. However, since we also capture y and drop it, the coroutine-closure is forced to be AsyncFnOnce. We must also force the capture of x to happen by-move. To determine this situation in particular, since unlike the last example the coroutine-kind's closure-kind has not yet been constrained, we must analyze the body of the coroutine-closure to see if how all of the upvars are used, to determine if they've been used in a way that is "consuming" -- i.e. that would force it to FnOnce29.

+ + +

Follow-up: When do async closures implement the regular Fn* traits?

+

Well, first of all, all async closures implement FnOnce since they can always be called at least once.

+

For Fn/FnMut, the detailed answer involves answering a related question: is the coroutine-closure lending? Because if it is, then it cannot implement the non-lending Fn/FnMut traits.

+

Determining when the coroutine-closure must lend its upvars is implemented in the should_reborrow_from_env_of_parent_coroutine_closure helper function30. Specifically, this needs to happen in two places:

+ +
    +
  1. Are we borrowing data owned by the parent closure? We can determine if that is the case by checking if the parent capture is by-move, EXCEPT if we apply a deref projection, which means we're reborrowing a reference that we captured by-move.
  2. +
+
#![allow(unused)]
+fn main() {
+let x = &1i32; // Let's call this lifetime `'1`.
+let c = async move || {
+    println!("{:?}", *x);
+    // Even though the inner coroutine borrows by ref, we're only capturing `*x`,
+    // not `x`, so the inner closure is allowed to reborrow the data for `'1`.
+};
+}
+
+
    +
  1. If a coroutine is mutably borrowing from a parent capture, then that mutable borrow cannot live for longer than either the parent or the borrow that we have on the original upvar. Therefore we always need to borrow the child capture with the lifetime of the parent coroutine-closure's env.
  2. +
+
#![allow(unused)]
+fn main() {
+let mut x = 1i32;
+let c = async || {
+    x = 1;
+    // The parent borrows `x` for some `&'1 mut i32`.
+    // However, when we call `c()`, we implicitly autoref for the signature of
+    // `AsyncFnMut::async_call_mut`. Let's call that lifetime `'call`. Since
+    // the maximum that `&'call mut &'1 mut i32` can be reborrowed is `&'call mut i32`,
+    // the inner coroutine should capture w/ the lifetime of the coroutine-closure.
+};
+}
+
+

If either of these cases apply, then we should capture the borrow with the lifetime of the parent coroutine-closure's env. Luckily, if this function is not correct, then the program is not unsound, since we still borrowck and validate the choices made from this function -- the only side-effect is that the user may receive unnecessary borrowck errors.

+

Instance resolution

+

If a coroutine-closure has a closure-kind of FnOnce, then its AsyncFnOnce::call_once and FnOnce::call_once implementations resolve to the coroutine-closure's body31, and the Future::poll of the coroutine that gets returned resolves to the body of the child closure.

+ +

If a coroutine-closure has a closure-kind of FnMut/Fn, then the same applies to AsyncFn and the corresponding Future implementation of the coroutine that gets returned.31 However, we use a MIR shim to generate the implementation of AsyncFnOnce::call_once/FnOnce::call_once32, and Fn::call/FnMut::call_mut instances if they exist33.

+ + +

This is represented by the ConstructCoroutineInClosureShim34. The receiver_by_ref bool will be true if this is the instance of Fn::call/FnMut::call_mut.35 The coroutine that all of these instances returns corresponds to the by-move body we will have synthesized by this point.36

+ + + +

Borrow-checking

+

It turns out that borrow-checking async closures is pretty straightforward. After adding a new DefiningTy::CoroutineClosure37 variant, and teaching borrowck how to generate the signature of the coroutine-closure38, borrowck proceeds totally fine.

+

One thing to note is that we don't borrow-check the synthetic body we make for by-move coroutines, since by construction (and the validity of the by-ref coroutine body it was derived from) it must be valid.

+ + + +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/crates-io.html b/crates-io.html new file mode 100644 index 000000000..181cf4a0d --- /dev/null +++ b/crates-io.html @@ -0,0 +1,220 @@ + + + + + + crates.io Dependencies - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

crates.io Dependencies

+

The Rust compiler supports building with some dependencies from crates.io. +Examples are log and env_logger.

+

In general, +you should avoid adding dependencies to the compiler for several reasons:

+
    +
  • The dependency may not be of high quality or well-maintained.
  • +
  • The dependency may not be using a compatible license.
  • +
  • The dependency may have transitive dependencies that have one of the above +problems.
  • +
+ +

Note that there is no official policy for vetting new dependencies to the compiler. +Decisions are made on a case-by-case basis, during code review.

+

Permitted dependencies

+

The tidy tool has a list of crates that are allowed. To add a +dependency that is not already in the compiler, you will need to add it to the list.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/css/chrome.css b/css/chrome.css new file mode 100644 index 000000000..10fa4b365 --- /dev/null +++ b/css/chrome.css @@ -0,0 +1,534 @@ +/* CSS for UI elements (a.k.a. chrome) */ + +@import 'variables.css'; + +::-webkit-scrollbar { + background: var(--bg); +} +::-webkit-scrollbar-thumb { + background: var(--scrollbar); +} +html { + scrollbar-color: var(--scrollbar) var(--bg); +} +#searchresults a, +.content a:link, +a:visited, +a > .hljs { + color: var(--links); +} + +/* Menu Bar */ + +#menu-bar, +#menu-bar-hover-placeholder { + z-index: 101; + margin: auto calc(0px - var(--page-padding)); +} +#menu-bar { + position: relative; + display: flex; + flex-wrap: wrap; + background-color: var(--bg); + border-bottom-color: var(--bg); + border-bottom-width: 1px; + border-bottom-style: solid; +} +#menu-bar.sticky, +.js #menu-bar-hover-placeholder:hover + #menu-bar, +.js #menu-bar:hover, +.js.sidebar-visible #menu-bar { + position: -webkit-sticky; + position: sticky; + top: 0 !important; +} +#menu-bar-hover-placeholder { + position: sticky; + position: -webkit-sticky; + top: 0; + height: var(--menu-bar-height); +} +#menu-bar.bordered { + border-bottom-color: var(--table-border-color); +} +#menu-bar i, #menu-bar .icon-button { + position: relative; + padding: 0 8px; + z-index: 10; + line-height: var(--menu-bar-height); + cursor: pointer; + transition: color 0.5s; +} +@media only screen and (max-width: 420px) { + #menu-bar i, #menu-bar .icon-button { + padding: 0 5px; + } +} + +.icon-button { + border: none; + background: none; + padding: 0; + color: inherit; +} +.icon-button i { + margin: 0; +} + +.right-buttons { + margin: 0 15px; +} +.right-buttons a { + text-decoration: none; +} + +.left-buttons { + display: flex; + margin: 0 5px; +} +.no-js .left-buttons { + display: none; +} + +.menu-title { + display: inline-block; + font-weight: 200; + font-size: 2.4rem; + line-height: var(--menu-bar-height); + text-align: center; + margin: 0; + flex: 1; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.js .menu-title { + cursor: pointer; +} + +.menu-bar, +.menu-bar:visited, +.nav-chapters, +.nav-chapters:visited, +.mobile-nav-chapters, +.mobile-nav-chapters:visited, +.menu-bar .icon-button, +.menu-bar a i { + color: var(--icons); +} + +.menu-bar i:hover, +.menu-bar .icon-button:hover, +.nav-chapters:hover, +.mobile-nav-chapters i:hover { + color: var(--icons-hover); +} + +/* Nav Icons */ + +.nav-chapters { + font-size: 2.5em; + text-align: center; + text-decoration: none; + + position: fixed; + top: 0; + bottom: 0; + margin: 0; + max-width: 150px; + min-width: 90px; + + display: flex; + justify-content: center; + align-content: center; + flex-direction: column; + + transition: color 0.5s, background-color 0.5s; +} + +.nav-chapters:hover { + text-decoration: none; + background-color: var(--theme-hover); + transition: background-color 0.15s, color 0.15s; +} + +.nav-wrapper { + margin-top: 50px; + display: none; +} + +.mobile-nav-chapters { + font-size: 2.5em; + text-align: center; + text-decoration: none; + width: 90px; + border-radius: 5px; + background-color: var(--sidebar-bg); +} + +.previous { + float: left; +} + +.next { + float: right; + right: var(--page-padding); +} + +@media only screen and (max-width: 1080px) { + .nav-wide-wrapper { display: none; } + .nav-wrapper { display: block; } +} + +@media only screen and (max-width: 1380px) { + .sidebar-visible .nav-wide-wrapper { display: none; } + .sidebar-visible .nav-wrapper { display: block; } +} + +/* Inline code */ + +:not(pre) > .hljs { + display: inline; + padding: 0.1em 0.3em; + border-radius: 3px; +} + +:not(pre):not(a) > .hljs { + color: var(--inline-code-color); + overflow-x: initial; +} + +a:hover > .hljs { + text-decoration: underline; +} + +pre { + position: relative; +} +pre > .buttons { + position: absolute; + z-index: 100; + right: 0px; + top: 2px; + margin: 0px; + padding: 2px 0px; + + color: var(--sidebar-fg); + cursor: pointer; + visibility: hidden; + opacity: 0; + transition: visibility 0.1s linear, opacity 0.1s linear; +} +pre:hover > .buttons { + visibility: visible; + opacity: 1 +} +pre > .buttons :hover { + color: var(--sidebar-active); + border-color: var(--icons-hover); + background-color: var(--theme-hover); +} +pre > .buttons i { + margin-left: 8px; +} +pre > .buttons button { + cursor: inherit; + margin: 0px 5px; + padding: 3px 5px; + font-size: 14px; + + border-style: solid; + border-width: 1px; + border-radius: 4px; + border-color: var(--icons); + background-color: var(--theme-popup-bg); + transition: 100ms; + transition-property: color,border-color,background-color; + color: var(--icons); +} +@media (pointer: coarse) { + pre > .buttons button { + /* On mobile, make it easier to tap buttons. */ + padding: 0.3rem 1rem; + } +} +pre > code { + padding: 1rem; +} + +/* FIXME: ACE editors overlap their buttons because ACE does absolute + positioning within the code block which breaks padding. The only solution I + can think of is to move the padding to the outer pre tag (or insert a div + wrapper), but that would require fixing a whole bunch of CSS rules. +*/ +.hljs.ace_editor { + padding: 0rem 0rem; +} + +pre > .result { + margin-top: 10px; +} + +/* Search */ + +#searchresults a { + text-decoration: none; +} + +mark { + border-radius: 2px; + padding: 0 3px 1px 3px; + margin: 0 -3px -1px -3px; + background-color: var(--search-mark-bg); + transition: background-color 300ms linear; + cursor: pointer; +} + +mark.fade-out { + background-color: rgba(0,0,0,0) !important; + cursor: auto; +} + +.searchbar-outer { + margin-left: auto; + margin-right: auto; + max-width: var(--content-max-width); +} + +#searchbar { + width: 100%; + margin: 5px auto 0px auto; + padding: 10px 16px; + transition: box-shadow 300ms ease-in-out; + border: 1px solid var(--searchbar-border-color); + border-radius: 3px; + background-color: var(--searchbar-bg); + color: var(--searchbar-fg); +} +#searchbar:focus, +#searchbar.active { + box-shadow: 0 0 3px var(--searchbar-shadow-color); +} + +.searchresults-header { + font-weight: bold; + font-size: 1em; + padding: 18px 0 0 5px; + color: var(--searchresults-header-fg); +} + +.searchresults-outer { + margin-left: auto; + margin-right: auto; + max-width: var(--content-max-width); + border-bottom: 1px dashed var(--searchresults-border-color); +} + +ul#searchresults { + list-style: none; + padding-left: 20px; +} +ul#searchresults li { + margin: 10px 0px; + padding: 2px; + border-radius: 2px; +} +ul#searchresults li.focus { + background-color: var(--searchresults-li-bg); +} +ul#searchresults span.teaser { + display: block; + clear: both; + margin: 5px 0 0 20px; + font-size: 0.8em; +} +ul#searchresults span.teaser em { + font-weight: bold; + font-style: normal; +} + +/* Sidebar */ + +.sidebar { + position: fixed; + left: 0; + top: 0; + bottom: 0; + width: var(--sidebar-width); + font-size: 0.875em; + box-sizing: border-box; + -webkit-overflow-scrolling: touch; + overscroll-behavior-y: contain; + background-color: var(--sidebar-bg); + color: var(--sidebar-fg); +} +.sidebar-resizing { + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; + user-select: none; +} +.js:not(.sidebar-resizing) .sidebar { + transition: transform 0.3s; /* Animation: slide away */ +} +.sidebar code { + line-height: 2em; +} +.sidebar .sidebar-scrollbox { + overflow-y: auto; + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + padding: 10px 10px; +} +.sidebar .sidebar-resize-handle { + position: absolute; + cursor: col-resize; + width: 0; + right: 0; + top: 0; + bottom: 0; +} +.js .sidebar .sidebar-resize-handle { + cursor: col-resize; + width: 5px; +} +.sidebar-hidden .sidebar { + transform: translateX(calc(0px - var(--sidebar-width))); +} +.sidebar::-webkit-scrollbar { + background: var(--sidebar-bg); +} +.sidebar::-webkit-scrollbar-thumb { + background: var(--scrollbar); +} + +.sidebar-visible .page-wrapper { + transform: translateX(var(--sidebar-width)); +} +@media only screen and (min-width: 620px) { + .sidebar-visible .page-wrapper { + transform: none; + margin-left: var(--sidebar-width); + } +} + +.chapter { + list-style: none outside none; + padding-left: 0; + line-height: 2.2em; +} + +.chapter ol { + width: 100%; +} + +.chapter li { + display: flex; + color: var(--sidebar-non-existant); +} +.chapter li a { + display: block; + padding: 0; + text-decoration: none; + color: var(--sidebar-fg); +} + +.chapter li a:hover { + color: var(--sidebar-active); +} + +.chapter li a.active { + color: var(--sidebar-active); +} + +.chapter li > a.toggle { + cursor: pointer; + display: block; + margin-left: auto; + padding: 0 10px; + user-select: none; + opacity: 0.68; +} + +.chapter li > a.toggle div { + transition: transform 0.5s; +} + +/* collapse the section */ +.chapter li:not(.expanded) + li > ol { + display: none; +} + +.chapter li.chapter-item { + line-height: 1.5em; + margin-top: 0.6em; +} + +.chapter li.expanded > a.toggle div { + transform: rotate(90deg); +} + +.spacer { + width: 100%; + height: 3px; + margin: 5px 0px; +} +.chapter .spacer { + background-color: var(--sidebar-spacer); +} + +@media (-moz-touch-enabled: 1), (pointer: coarse) { + .chapter li a { padding: 5px 0; } + .spacer { margin: 10px 0; } +} + +.section { + list-style: none outside none; + padding-left: 20px; + line-height: 1.9em; +} + +/* Theme Menu Popup */ + +.theme-popup { + position: absolute; + left: 10px; + top: var(--menu-bar-height); + z-index: 1000; + border-radius: 4px; + font-size: 0.7em; + color: var(--fg); + background: var(--theme-popup-bg); + border: 1px solid var(--theme-popup-border); + margin: 0; + padding: 0; + list-style: none; + display: none; +} +.theme-popup .default { + color: var(--icons); +} +.theme-popup .theme { + width: 100%; + border: 0; + margin: 0; + padding: 2px 10px; + line-height: 25px; + white-space: nowrap; + text-align: left; + cursor: pointer; + color: inherit; + background: inherit; + font-size: inherit; +} +.theme-popup .theme:hover { + background-color: var(--theme-hover); +} +.theme-popup .theme:hover:first-child, +.theme-popup .theme:hover:last-child { + border-top-left-radius: inherit; + border-top-right-radius: inherit; +} diff --git a/css/general.css b/css/general.css new file mode 100644 index 000000000..0e4f07a50 --- /dev/null +++ b/css/general.css @@ -0,0 +1,191 @@ +/* Base styles and content styles */ + +@import 'variables.css'; + +:root { + /* Browser default font-size is 16px, this way 1 rem = 10px */ + font-size: 62.5%; +} + +html { + font-family: "Open Sans", sans-serif; + color: var(--fg); + background-color: var(--bg); + text-size-adjust: none; + -webkit-text-size-adjust: none; +} + +body { + margin: 0; + font-size: 1.6rem; + overflow-x: hidden; +} + +code { + font-family: "Source Code Pro", Consolas, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace, monospace !important; + font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */ +} + +/* make long words/inline code not x overflow */ +main { + overflow-wrap: break-word; +} + +/* make wide tables scroll if they overflow */ +.table-wrapper { + overflow-x: auto; +} + +/* Don't change font size in headers. */ +h1 code, h2 code, h3 code, h4 code, h5 code, h6 code { + font-size: unset; +} + +.left { float: left; } +.right { float: right; } +.boring { opacity: 0.6; } +.hide-boring .boring { display: none; } +.hidden { display: none !important; } + +h2, h3 { margin-top: 2.5em; } +h4, h5 { margin-top: 2em; } + +.header + .header h3, +.header + .header h4, +.header + .header h5 { + margin-top: 1em; +} + +h1:target::before, +h2:target::before, +h3:target::before, +h4:target::before, +h5:target::before, +h6:target::before { + display: inline-block; + content: "»"; + margin-left: -30px; + width: 30px; +} + +/* This is broken on Safari as of version 14, but is fixed + in Safari Technology Preview 117 which I think will be Safari 14.2. + https://bugs.webkit.org/show_bug.cgi?id=218076 +*/ +:target { + scroll-margin-top: calc(var(--menu-bar-height) + 0.5em); +} + +.page { + outline: 0; + padding: 0 var(--page-padding); + margin-top: calc(0px - var(--menu-bar-height)); /* Compensate for the #menu-bar-hover-placeholder */ +} +.page-wrapper { + box-sizing: border-box; +} +.js:not(.sidebar-resizing) .page-wrapper { + transition: margin-left 0.3s ease, transform 0.3s ease; /* Animation: slide away */ +} + +.content { + overflow-y: auto; + padding: 0 5px 50px 5px; +} +.content main { + margin-left: auto; + margin-right: auto; + max-width: var(--content-max-width); +} +.content p { line-height: 1.45em; } +.content ol { line-height: 1.45em; } +.content ul { line-height: 1.45em; } +.content a { text-decoration: none; } +.content a:hover { text-decoration: underline; } +.content img, .content video { max-width: 100%; } +.content .header:link, +.content .header:visited { + color: var(--fg); +} +.content .header:link, +.content .header:visited:hover { + text-decoration: none; +} + +table { + margin: 0 auto; + border-collapse: collapse; +} +table td { + padding: 3px 20px; + border: 1px var(--table-border-color) solid; +} +table thead { + background: var(--table-header-bg); +} +table thead td { + font-weight: 700; + border: none; +} +table thead th { + padding: 3px 20px; +} +table thead tr { + border: 1px var(--table-header-bg) solid; +} +/* Alternate background colors for rows */ +table tbody tr:nth-child(2n) { + background: var(--table-alternate-bg); +} + + +blockquote { + margin: 20px 0; + padding: 0 20px; + color: var(--fg); + background-color: var(--quote-bg); + border-top: .1em solid var(--quote-border); + border-bottom: .1em solid var(--quote-border); +} + + +:not(.footnote-definition) + .footnote-definition, +.footnote-definition + :not(.footnote-definition) { + margin-top: 2em; +} +.footnote-definition { + font-size: 0.9em; + margin: 0.5em 0; +} +.footnote-definition p { + display: inline; +} + +.tooltiptext { + position: absolute; + visibility: hidden; + color: #fff; + background-color: #333; + transform: translateX(-50%); /* Center by moving tooltip 50% of its width left */ + left: -8px; /* Half of the width of the icon */ + top: -35px; + font-size: 0.8em; + text-align: center; + border-radius: 6px; + padding: 5px 8px; + margin: 5px; + z-index: 1000; +} +.tooltipped .tooltiptext { + visibility: visible; +} + +.chapter li.part-title { + color: var(--sidebar-fg); + margin: 5px 0px; + font-weight: bold; +} + +.result-no-output { + font-style: italic; +} diff --git a/css/print.css b/css/print.css new file mode 100644 index 000000000..5e690f755 --- /dev/null +++ b/css/print.css @@ -0,0 +1,54 @@ + +#sidebar, +#menu-bar, +.nav-chapters, +.mobile-nav-chapters { + display: none; +} + +#page-wrapper.page-wrapper { + transform: none; + margin-left: 0px; + overflow-y: initial; +} + +#content { + max-width: none; + margin: 0; + padding: 0; +} + +.page { + overflow-y: initial; +} + +code { + background-color: #666666; + border-radius: 5px; + + /* Force background to be printed in Chrome */ + -webkit-print-color-adjust: exact; +} + +pre > .buttons { + z-index: 2; +} + +a, a:visited, a:active, a:hover { + color: #4183c4; + text-decoration: none; +} + +h1, h2, h3, h4, h5, h6 { + page-break-inside: avoid; + page-break-after: avoid; +} + +pre, code { + page-break-inside: avoid; + white-space: pre-wrap; +} + +.fa { + display: none !important; +} diff --git a/css/variables.css b/css/variables.css new file mode 100644 index 000000000..56b634bc3 --- /dev/null +++ b/css/variables.css @@ -0,0 +1,253 @@ + +/* Globals */ + +:root { + --sidebar-width: 300px; + --page-padding: 15px; + --content-max-width: 750px; + --menu-bar-height: 50px; +} + +/* Themes */ + +.ayu { + --bg: hsl(210, 25%, 8%); + --fg: #c5c5c5; + + --sidebar-bg: #14191f; + --sidebar-fg: #c8c9db; + --sidebar-non-existant: #5c6773; + --sidebar-active: #ffb454; + --sidebar-spacer: #2d334f; + + --scrollbar: var(--sidebar-fg); + + --icons: #737480; + --icons-hover: #b7b9cc; + + --links: #0096cf; + + --inline-code-color: #ffb454; + + --theme-popup-bg: #14191f; + --theme-popup-border: #5c6773; + --theme-hover: #191f26; + + --quote-bg: hsl(226, 15%, 17%); + --quote-border: hsl(226, 15%, 22%); + + --table-border-color: hsl(210, 25%, 13%); + --table-header-bg: hsl(210, 25%, 28%); + --table-alternate-bg: hsl(210, 25%, 11%); + + --searchbar-border-color: #848484; + --searchbar-bg: #424242; + --searchbar-fg: #fff; + --searchbar-shadow-color: #d4c89f; + --searchresults-header-fg: #666; + --searchresults-border-color: #888; + --searchresults-li-bg: #252932; + --search-mark-bg: #e3b171; +} + +.coal { + --bg: hsl(200, 7%, 8%); + --fg: #98a3ad; + + --sidebar-bg: #292c2f; + --sidebar-fg: #a1adb8; + --sidebar-non-existant: #505254; + --sidebar-active: #3473ad; + --sidebar-spacer: #393939; + + --scrollbar: var(--sidebar-fg); + + --icons: #43484d; + --icons-hover: #b3c0cc; + + --links: #2b79a2; + + --inline-code-color: #c5c8c6; + + --theme-popup-bg: #141617; + --theme-popup-border: #43484d; + --theme-hover: #1f2124; + + --quote-bg: hsl(234, 21%, 18%); + --quote-border: hsl(234, 21%, 23%); + + --table-border-color: hsl(200, 7%, 13%); + --table-header-bg: hsl(200, 7%, 28%); + --table-alternate-bg: hsl(200, 7%, 11%); + + --searchbar-border-color: #aaa; + --searchbar-bg: #b7b7b7; + --searchbar-fg: #000; + --searchbar-shadow-color: #aaa; + --searchresults-header-fg: #666; + --searchresults-border-color: #98a3ad; + --searchresults-li-bg: #2b2b2f; + --search-mark-bg: #355c7d; +} + +.light { + --bg: hsl(0, 0%, 100%); + --fg: hsl(0, 0%, 0%); + + --sidebar-bg: #fafafa; + --sidebar-fg: hsl(0, 0%, 0%); + --sidebar-non-existant: #aaaaaa; + --sidebar-active: #1f1fff; + --sidebar-spacer: #f4f4f4; + + --scrollbar: #8F8F8F; + + --icons: #747474; + --icons-hover: #000000; + + --links: #20609f; + + --inline-code-color: #301900; + + --theme-popup-bg: #fafafa; + --theme-popup-border: #cccccc; + --theme-hover: #e6e6e6; + + --quote-bg: hsl(197, 37%, 96%); + --quote-border: hsl(197, 37%, 91%); + + --table-border-color: hsl(0, 0%, 95%); + --table-header-bg: hsl(0, 0%, 80%); + --table-alternate-bg: hsl(0, 0%, 97%); + + --searchbar-border-color: #aaa; + --searchbar-bg: #fafafa; + --searchbar-fg: #000; + --searchbar-shadow-color: #aaa; + --searchresults-header-fg: #666; + --searchresults-border-color: #888; + --searchresults-li-bg: #e4f2fe; + --search-mark-bg: #a2cff5; +} + +.navy { + --bg: hsl(226, 23%, 11%); + --fg: #bcbdd0; + + --sidebar-bg: #282d3f; + --sidebar-fg: #c8c9db; + --sidebar-non-existant: #505274; + --sidebar-active: #2b79a2; + --sidebar-spacer: #2d334f; + + --scrollbar: var(--sidebar-fg); + + --icons: #737480; + --icons-hover: #b7b9cc; + + --links: #2b79a2; + + --inline-code-color: #c5c8c6; + + --theme-popup-bg: #161923; + --theme-popup-border: #737480; + --theme-hover: #282e40; + + --quote-bg: hsl(226, 15%, 17%); + --quote-border: hsl(226, 15%, 22%); + + --table-border-color: hsl(226, 23%, 16%); + --table-header-bg: hsl(226, 23%, 31%); + --table-alternate-bg: hsl(226, 23%, 14%); + + --searchbar-border-color: #aaa; + --searchbar-bg: #aeaec6; + --searchbar-fg: #000; + --searchbar-shadow-color: #aaa; + --searchresults-header-fg: #5f5f71; + --searchresults-border-color: #5c5c68; + --searchresults-li-bg: #242430; + --search-mark-bg: #a2cff5; +} + +.rust { + --bg: hsl(60, 9%, 87%); + --fg: #262625; + + --sidebar-bg: #3b2e2a; + --sidebar-fg: #c8c9db; + --sidebar-non-existant: #505254; + --sidebar-active: #e69f67; + --sidebar-spacer: #45373a; + + --scrollbar: var(--sidebar-fg); + + --icons: #737480; + --icons-hover: #262625; + + --links: #2b79a2; + + --inline-code-color: #6e6b5e; + + --theme-popup-bg: #e1e1db; + --theme-popup-border: #b38f6b; + --theme-hover: #99908a; + + --quote-bg: hsl(60, 5%, 75%); + --quote-border: hsl(60, 5%, 70%); + + --table-border-color: hsl(60, 9%, 82%); + --table-header-bg: #b3a497; + --table-alternate-bg: hsl(60, 9%, 84%); + + --searchbar-border-color: #aaa; + --searchbar-bg: #fafafa; + --searchbar-fg: #000; + --searchbar-shadow-color: #aaa; + --searchresults-header-fg: #666; + --searchresults-border-color: #888; + --searchresults-li-bg: #dec2a2; + --search-mark-bg: #e69f67; +} + +@media (prefers-color-scheme: dark) { + .light.no-js { + --bg: hsl(200, 7%, 8%); + --fg: #98a3ad; + + --sidebar-bg: #292c2f; + --sidebar-fg: #a1adb8; + --sidebar-non-existant: #505254; + --sidebar-active: #3473ad; + --sidebar-spacer: #393939; + + --scrollbar: var(--sidebar-fg); + + --icons: #43484d; + --icons-hover: #b3c0cc; + + --links: #2b79a2; + + --inline-code-color: #c5c8c6; + + --theme-popup-bg: #141617; + --theme-popup-border: #43484d; + --theme-hover: #1f2124; + + --quote-bg: hsl(234, 21%, 18%); + --quote-border: hsl(234, 21%, 23%); + + --table-border-color: hsl(200, 7%, 13%); + --table-header-bg: hsl(200, 7%, 28%); + --table-alternate-bg: hsl(200, 7%, 11%); + + --searchbar-border-color: #aaa; + --searchbar-bg: #b7b7b7; + --searchbar-fg: #000; + --searchbar-shadow-color: #aaa; + --searchresults-header-fg: #666; + --searchresults-border-color: #98a3ad; + --searchresults-li-bg: #2b2b2f; + --search-mark-bg: #355c7d; + } +} diff --git a/debugging-support-in-rustc.html b/debugging-support-in-rustc.html new file mode 100644 index 000000000..b5520abc8 --- /dev/null +++ b/debugging-support-in-rustc.html @@ -0,0 +1,532 @@ + + + + + + Debugging support in the Rust compiler - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Debugging support in the Rust compiler

+ +

This document explains the state of debugging tools support in the Rust compiler (rustc). +It gives an overview of GDB, LLDB, WinDbg/CDB, +as well as infrastructure around Rust compiler to debug Rust code. +If you want to learn how to debug the Rust compiler itself, +see Debugging the Compiler.

+

The material is gathered from the video, +Tom Tromey discusses debugging support in rustc.

+

Preliminaries

+

Debuggers

+

According to Wikipedia

+
+

A debugger or debugging tool is a computer program that is used to test and debug +other programs (the "target" program).

+
+

Writing a debugger from scratch for a language requires a lot of work, especially if +debuggers have to be supported on various platforms. GDB and LLDB, however, can be +extended to support debugging a language. This is the path that Rust has chosen. +This document's main goal is to document the said debuggers support in Rust compiler.

+

DWARF

+

According to the DWARF standard website

+
+

DWARF is a debugging file format used by many compilers and debuggers to support source level +debugging. It addresses the requirements of a number of procedural languages, +such as C, C++, and Fortran, and is designed to be extensible to other languages. +DWARF is architecture independent and applicable to any processor or operating system. +It is widely used on Unix, Linux and other operating systems, +as well as in stand-alone environments.

+
+

DWARF reader is a program that consumes the DWARF format and creates debugger compatible output. +This program may live in the compiler itself. DWARF uses a data structure called +Debugging Information Entry (DIE) which stores the information as "tags" to denote functions, +variables etc., e.g., DW_TAG_variable, DW_TAG_pointer_type, DW_TAG_subprogram etc. +You can also invent your own tags and attributes.

+

CodeView/PDB

+

PDB (Program Database) is a file format created by Microsoft that contains debug information. +PDBs can be consumed by debuggers such as WinDbg/CDB and other tools to display debug information. +A PDB contains multiple streams that describe debug information about a specific binary such +as types, symbols, and source files used to compile the given binary. CodeView is another +format which defines the structure of symbol records and type records that appear within +PDB streams.

+

Supported debuggers

+

GDB

+

Rust expression parser

+

To be able to show debug output, we need an expression parser. +This (GDB) expression parser is written in Bison, +and can parse only a subset of Rust expressions. +GDB parser was written from scratch and has no relation to any other parser, +including that of rustc.

+

GDB has Rust-like value and type output. It can print values and types in a way +that look like Rust syntax in the output. Or when you print a type as ptype in GDB, +it also looks like Rust source code. Checkout the documentation in the manual for GDB/Rust.

+

Parser extensions

+

Expression parser has a couple of extensions in it to facilitate features that you cannot do +with Rust. Some limitations are listed in the manual for GDB/Rust. There is some special +code in the DWARF reader in GDB to support the extensions.

+

A couple of examples of DWARF reader support needed are as follows:

+
    +
  1. +

    Enum: Needed for support for enum types. +The Rust compiler writes the information about enum into DWARF, +and GDB reads the DWARF to understand where is the tag field, +or if there is a tag field, +or if the tag slot is shared with non-zero optimization etc.

    +
  2. +
  3. +

    Dissect trait objects: DWARF extension where the trait object's description in the DWARF +also points to a stub description of the corresponding vtable which in turn points to the +concrete type for which this trait object exists. This means that you can do a print *object +for that trait object, and GDB will understand how to find the correct type of the payload in +the trait object.

    +
  4. +
+

TODO: Figure out if the following should be mentioned in the GDB-Rust document rather than +this guide page so there is no duplication. This is regarding the following comments:

+

This comment by Tom

+
+

gdb's Rust extensions and limitations are documented in the gdb manual: +https://sourceware.org/gdb/onlinedocs/gdb/Rust.html -- however, this neglects to mention that +gdb convenience variables and registers follow the gdb $ convention, and that the Rust parser +implements the gdb @ extension.

+
+

This question by Aman

+
+

@tromey do you think we should mention this part in the GDB-Rust document rather than this +document so there is no duplication etc.?

+
+

LLDB

+

Rust expression parser

+

This expression parser is written in C++. It is a type of Recursive Descent parser. +It implements slightly less of the Rust language than GDB. +LLDB has Rust-like value and type output.

+

Developer notes

+
    +
  • LLDB has a plugin architecture but that does not work for language support.
  • +
  • GDB generally works better on Linux.
  • +
+

WinDbg/CDB

+

Microsoft provides Windows Debugging Tools such as the Windows Debugger (WinDbg) and +the Console Debugger (CDB) which both support debugging programs written in Rust. These +debuggers parse the debug info for a binary from the PDB, if available, to construct a +visualization to serve up in the debugger.

+

Natvis

+

Both WinDbg and CDB support defining and viewing custom visualizations for any given type +within the debugger using the Natvis framework. The Rust compiler defines a set of Natvis +files that define custom visualizations for a subset of types in the standard libraries such +as, std, core, and alloc. These Natvis files are embedded into PDBs generated by the +*-pc-windows-msvc target triples to automatically enable these custom visualizations when +debugging. This default can be overridden by setting the strip rustc flag to either debuginfo +or symbols.

+

Rust has support for embedding Natvis files for crates outside of the standard libraries by +using the #[debugger_visualizer] attribute. +For more details on how to embed debugger visualizers, +please refer to the section on the debugger_visualizer attribute.

+

DWARF and rustc

+

DWARF is the standard way compilers generate debugging information that debuggers read. +It is the debugging format on macOS and Linux. +It is a multi-language and extensible format, +and is mostly good enough for Rust's purposes. +Hence, the current implementation reuses DWARF's concepts. +This is true even if some of the concepts in DWARF do not align with Rust semantically because, +generally, there can be some kind of mapping between the two.

+

We have some DWARF extensions that the Rust compiler emits and the debuggers understand that +are not in the DWARF standard.

+
    +
  • +

    Rust compiler will emit DWARF for a virtual table, and this vtable object will have a +DW_AT_containing_type that points to the real type. This lets debuggers dissect a trait object +pointer to correctly find the payload. E.g., here's such a DIE, from a test case in the gdb +repository:

    +
    <1><1a9>: Abbrev Number: 3 (DW_TAG_structure_type)
    +   <1aa>   DW_AT_containing_type: <0x1b4>
    +   <1ae>   DW_AT_name        : (indirect string, offset: 0x23d): vtable
    +   <1b2>   DW_AT_byte_size   : 0
    +   <1b3>   DW_AT_alignment   : 8
    +
    +
  • +
  • +

    The other extension is that the Rust compiler can emit a tagless discriminated union. +See DWARF feature request for this item.

    +
  • +
+

Current limitations of DWARF

+
    +
  • Traits - require a bigger change than normal to DWARF, on how to represent Traits in DWARF.
  • +
  • DWARF provides no way to differentiate between Structs and Tuples. Rust compiler emits +fields with __0 and debuggers look for a sequence of such names to overcome this limitation. +For example, in this case the debugger would look at a field via x.__0 instead of x.0. +This is resolved via the Rust parser in the debugger so now you can do x.0.
  • +
+

DWARF relies on debuggers to know some information about platform ABI. +Rust does not do that all the time.

+

Developer notes

+

This section is from the talk about certain aspects of development.

+

What is missing

+

Code signing for LLDB debug server on macOS

+

According to Wikipedia, System Integrity Protection is

+
+

System Integrity Protection (SIP, sometimes referred to as rootless) is a security feature +of Apple's macOS operating system introduced in OS X El Capitan. It comprises a number of +mechanisms that are enforced by the kernel. A centerpiece is the protection of system-owned +files and directories against modifications by processes without a specific "entitlement", +even when executed by the root user or a user with root privileges (sudo).

+
+

It prevents processes using ptrace syscall. If a process wants to use ptrace it has to be +code signed. The certificate that signs it has to be trusted on your machine.

+

See Apple developer documentation for System Integrity Protection.

+

We may need to sign up with Apple and get the keys to do this signing. Tom has looked into if +Mozilla cannot do this because it is at the maximum number of +keys it is allowed to sign. Tom does not know if Mozilla could get more keys.

+

Alternatively, Tom suggests that maybe a Rust legal entity is needed to get the keys via Apple. +This problem is not technical in nature. If we had such a key we could sign GDB as well and +ship that.

+

DWARF and Traits

+

Rust traits are not emitted into DWARF at all. The impact of this is calling a method x.method() +does not work as is. The reason being that method is implemented by a trait, as opposed +to a type. That information is not present so finding trait methods is missing.

+

DWARF has a notion of interface types (possibly added for Java). Tom's idea was to use this +interface type as traits.

+

DWARF only deals with concrete names, not the reference types. So, a given implementation of a +trait for a type would be one of these interfaces (DW_tag_interface type). Also, the type for +which it is implemented would describe all the interfaces this type implements. This requires a +DWARF extension.

+

Issue on Github: https://github.com/rust-lang/rust/issues/33014

+

Typical process for a Debug Info change (LLVM)

+

LLVM has Debug Info (DI) builders. This is the primary thing that Rust calls into. +This is why we need to change LLVM first because that is emitted first and not DWARF directly. +This is a kind of metadata that you construct and hand-off to LLVM. For the Rustc/LLVM hand-off +some LLVM DI builder methods are called to construct representation of a type.

+

The steps of this process are as follows:

+
    +
  1. +

    LLVM needs changing.

    +

    LLVM does not emit Interface types at all, so this needs to be implemented in the LLVM first.

    +

    Get sign off on LLVM maintainers that this is a good idea.

    +
  2. +
  3. +

    Change the DWARF extension.

    +
  4. +
  5. +

    Update the debuggers.

    +

    Update DWARF readers, expression evaluators.

    +
  6. +
  7. +

    Update Rust compiler.

    +

    Change it to emit this new information.

    +
  8. +
+

Procedural macro stepping

+

A deeply profound question is that how do you actually debug a procedural macro? +What is the location you emit for a macro expansion? Consider some of the following cases -

+
    +
  • You can emit location of the invocation of the macro.
  • +
  • You can emit the location of the definition of the macro.
  • +
  • You can emit locations of the content of the macro.
  • +
+

RFC: https://github.com/rust-lang/rfcs/pull/2117

+

Focus is to let macros decide what to do. This can be achieved by having some kind of attribute +that lets the macro tell the compiler where the line marker should be. This affects where you +set the breakpoints and what happens when you step it.

+

Source file checksums in debug info

+

Both DWARF and CodeView (PDB) support embedding a cryptographic hash of each source file that +contributed to the associated binary.

+

The cryptographic hash can be used by a debugger to verify that the source file matches the +executable. If the source file does not match, the debugger can provide a warning to the user.

+

The hash can also be used to prove that a given source file has not been modified since it was +used to compile an executable. Because MD5 and SHA1 both have demonstrated vulnerabilities, +using SHA256 is recommended for this application.

+

The Rust compiler stores the hash for each source file in the corresponding SourceFile in +the SourceMap. The hashes of input files to external crates are stored in rlib metadata.

+

A default hashing algorithm is set in the target specification. This allows the target to +specify the best hash available, since not all targets support all hash algorithms.

+

The hashing algorithm for a target can also be overridden with the -Z source-file-checksum= +command-line option.

+

DWARF 5

+

DWARF version 5 supports embedding an MD5 hash to validate the source file version in use. +DWARF 5 - Section 6.2.4.1 opcode DW_LNCT_MD5

+

LLVM

+

LLVM IR supports MD5 and SHA1 (and SHA256 in LLVM 11+) source file checksums in the DIFile node.

+

LLVM DIFile documentation

+

Microsoft Visual C++ Compiler /ZH option

+

The MSVC compiler supports embedding MD5, SHA1, or SHA256 hashes in the PDB using the /ZH +compiler option.

+

MSVC /ZH documentation

+

Clang

+

Clang always embeds an MD5 checksum, though this does not appear in documentation.

+

Future work

+

Name mangling changes

+
    +
  • New demangler in libiberty (gcc source tree).
  • +
  • New demangler in LLVM or LLDB.
  • +
+

TODO: Check the location of the demangler source. #1157

+

Reuse Rust compiler for expressions

+

This is an important idea because debuggers by and large do not try to implement type +inference. You need to be much more explicit when you type into the debugger than your +actual source code. So, you cannot just copy and paste an expression from your source +code to debugger and expect the same answer but this would be nice. This can be helped +by using compiler.

+

It is certainly doable but it is a large project. You certainly need a bridge to the +debugger because the debugger alone has access to the memory. Both GDB (gcc) and LLDB (clang) +have this feature. LLDB uses Clang to compile code to JIT and GDB can do the same with GCC.

+

Both debuggers expression evaluation implement both a superset and a subset of Rust. +They implement just the expression language, +but they also add some extensions like GDB has convenience variables. +Therefore, if you are taking this route, +then you not only need to do this bridge, +but may have to add some mode to let the compiler understand some extensions.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/diagnostics.html b/diagnostics.html new file mode 100644 index 000000000..f67ad2ff3 --- /dev/null +++ b/diagnostics.html @@ -0,0 +1,1102 @@ + + + + + + Errors and Lints - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Errors and Lints

+ +

A lot of effort has been put into making rustc have great error messages. +This chapter is about how to emit compile errors and lints from the compiler.

+

Diagnostic structure

+

The main parts of a diagnostic error are the following:

+
error[E0000]: main error message
+  --> file.rs:LL:CC
+   |
+LL | <code>
+   | -^^^^- secondary label
+   |  |
+   |  primary label
+   |
+   = note: note without a `Span`, created with `.note`
+note: sub-diagnostic message for `.span_note`
+  --> file.rs:LL:CC
+   |
+LL | more code
+   |      ^^^^
+
+
    +
  • Level (error, warning, etc.). It indicates the severity of the message. +(See diagnostic levels)
  • +
  • Code (for example, for "mismatched types", it is E0308). It helps +users get more information about the current error through an extended +description of the problem in the error code index. Not all diagnostic have a +code. For example, diagnostics created by lints don't have one.
  • +
  • Message. It is the main description of the problem. It should be general and +able to stand on its own, so that it can make sense even in isolation.
  • +
  • Diagnostic window. This contains several things: +
      +
    • The path, line number and column of the beginning of the primary span.
    • +
    • The users' affected code and its surroundings.
    • +
    • Primary and secondary spans underlying the users' code. These spans can +optionally contain one or more labels. +
        +
      • Primary spans should have enough text to describe the problem in such a +way that if it were the only thing being displayed (for example, in an +IDE) it would still make sense. Because it is "spatially aware" (it +points at the code), it can generally be more succinct than the error +message.
      • +
      • If cluttered output can be foreseen in cases when multiple span labels +overlap, it is a good idea to tweak the output appropriately. For +example, the if/else arms have incompatible types error uses different +spans depending on whether the arms are all in the same line, if one of +the arms is empty and if none of those cases applies.
      • +
      +
    • +
    +
  • +
  • Sub-diagnostics. Any error can have multiple sub-diagnostics that look +similar to the main part of the error. These are used for cases where the +order of the explanation might not correspond with the order of the code. If +the order of the explanation can be "order free", leveraging secondary labels +in the main diagnostic is preferred, as it is typically less verbose.
  • +
+

The text should be matter of fact and avoid capitalization and periods, unless +multiple sentences are needed:

+
error: the fobrulator needs to be krontrificated
+
+

When code or an identifier must appear in a message or label, it should be +surrounded with backticks:

+
error: the identifier `foo.bar` is invalid
+
+

Error codes and explanations

+

Most errors have an associated error code. Error codes are linked to long-form +explanations which contains an example of how to trigger the error and in-depth +details about the error. They may be viewed with the --explain flag, or via +the error index.

+

As a general rule, give an error a code (with an associated explanation) if the +explanation would give more information than the error itself. A lot of the time +it's better to put all the information in the emitted error itself. However, +sometimes that would make the error verbose or there are too many possible +triggers to include useful information for all cases in the error, in which case +it's a good idea to add an explanation.1 +As always, if you are not sure, just ask your reviewer!

+

If you decide to add a new error with an associated error code, please read +this section for a guide and important details about the +process.

+
1 +

This rule of thumb was suggested by @estebank here.

+
+

Lints versus fixed diagnostics

+

Some messages are emitted via lints, where the user can control the +level. Most diagnostics are hard-coded such that the user cannot control the +level.

+

Usually it is obvious whether a diagnostic should be "fixed" or a lint, but +there are some grey areas.

+

Here are a few examples:

+
    +
  • Borrow checker errors: these are fixed errors. The user cannot adjust the +level of these diagnostics to silence the borrow checker.
  • +
  • Dead code: this is a lint. While the user probably doesn't want dead code in +their crate, making this a hard error would make refactoring and development +very painful.
  • +
  • future-incompatible lints: +these are silencable lints. +It was decided that making them fixed errors would cause too much breakage, +so warnings are instead emitted, +and will eventually be turned into fixed (hard) errors.
  • +
+

Hard-coded warnings (those using methods like span_warn) should be avoided +for normal code, preferring to use lints instead. Some cases, such as warnings +with CLI flags, will require the use of hard-coded warnings.

+

See the deny lint level below for guidelines when to +use an error-level lint instead of a fixed error.

+

Diagnostic output style guide

+
    +
  • Write in plain simple English. If your message, when shown on a – possibly +small – screen (which hasn't been cleaned for a while), cannot be understood +by a normal programmer, who just came out of bed after a night partying, +it's too complex.
  • +
  • Error, Warning, Note, and Help messages start with a lowercase +letter and do not end with punctuation.
  • +
  • Error messages should be succinct. Users will see these error messages many +times, and more verbose descriptions can be viewed with the --explain +flag. That said, don't make it so terse that it's hard to understand.
  • +
  • The word "illegal" is illegal. Prefer "invalid" or a more specific word +instead.
  • +
  • Errors should document the span of code where they occur (use +rustc_errors::DiagCtxt's +span_* methods or a diagnostic struct's #[primary_span] to easily do +this). Also note other spans that have contributed to the error if the span +isn't too large.
  • +
  • When emitting a message with span, try to reduce the span to the smallest +amount possible that still signifies the issue
  • +
  • Try not to emit multiple error messages for the same error. This may require +detecting duplicates.
  • +
  • When the compiler has too little information for a specific error message, +consult with the compiler team to add new attributes for library code that +allow adding more information. For example see +#[rustc_on_unimplemented]. Use these +annotations when available!
  • +
  • Keep in mind that Rust's learning curve is rather steep, and that the +compiler messages are an important learning tool.
  • +
  • When talking about the compiler, call it the compiler, not Rust or +rustc.
  • +
  • Use the Oxford comma when +writing lists of items.
  • +
+

Lint naming

+

From RFC 0344, lint names should be consistent, with the following +guidelines:

+

The basic rule is: the lint name should make sense when read as "allow +lint-name" or "allow lint-name items". For example, "allow +deprecated items" and "allow dead_code" makes sense, while "allow +unsafe_block" is ungrammatical (should be plural).

+
    +
  • +

    Lint names should state the bad thing being checked for, e.g. deprecated, +so that #[allow(deprecated)] (items) reads correctly. Thus ctypes is not +an appropriate name; improper_ctypes is.

    +
  • +
  • +

    Lints that apply to arbitrary items (like the stability lints) should just +mention what they check for: use deprecated rather than +deprecated_items. This keeps lint names short. (Again, think "allow +lint-name items".)

    +
  • +
  • +

    If a lint applies to a specific grammatical class, mention that class and +use the plural form: use unused_variables rather than unused_variable. +This makes #[allow(unused_variables)] read correctly.

    +
  • +
  • +

    Lints that catch unnecessary, unused, or useless aspects of code should use +the term unused, e.g. unused_imports, unused_typecasts.

    +
  • +
  • +

    Use snake case in the same way you would for function names.

    +
  • +
+

Diagnostic levels

+

Guidelines for different diagnostic levels:

+
    +
  • +

    error: emitted when the compiler detects a problem that makes it unable to +compile the program, either because the program is invalid or the programmer +has decided to make a specific warning into an error.

    +
  • +
  • +

    warning: emitted when the compiler detects something odd about a program. +Care should be taken when adding warnings to avoid warning fatigue, and +avoid false-positives where there really isn't a problem with the code. Some +examples of when it is appropriate to issue a warning:

    +
      +
    • A situation where the user should take action, such as swap out a +deprecated item, or use a Result, but otherwise doesn't prevent +compilation.
    • +
    • Unnecessary syntax that can be removed without affecting the semantics of +the code. For example, unused code, or unnecessary unsafe.
    • +
    • Code that is very likely to be incorrect, dangerous, or confusing, but the +language technically allows, and is not ready or confident enough to make +an error. For example unused_comparisons (out of bounds comparisons) or +bindings_with_variant_name (the user likely did not intend to create a +binding in a pattern).
    • +
    • Future-incompatible lints, where something was +accidentally or erroneously accepted in the past, but rejecting would +cause excessive breakage in the ecosystem.
    • +
    • Stylistic choices. For example, camel or snake case, or the dyn trait +warning in the 2018 edition. These have a high bar to be added, and should +only be used in exceptional circumstances. Other stylistic choices should +either be allow-by-default lints, or part of other tools like Clippy or +rustfmt.
    • +
    +
  • +
  • +

    help: emitted following an error or warning to give additional +information to the user about how to solve their problem. These messages +often include a suggestion string and rustc_errors::Applicability +confidence level to guide automated source fixes by tools. See the +Suggestions section for more details.

    +

    The error or warning portion should not suggest how to fix the problem, +only the "help" sub-diagnostic should.

    +
  • +
  • +

    note: emitted to given more context and identify additional circumstances +and parts of the code that caused the warning or error. For example, the +borrow checker will note any previous conflicting borrows.

    +

    help vs note: help should be used to show changes the user can +possibly make to fix the problem. note should be used for everything else, +such as other context, information and facts, online resources to read, etc.

    +
  • +
+

Not to be confused with lint levels, whose guidelines are:

+
    +
  • +

    forbid: Lints should never default to forbid.

    +
  • +
  • +

    deny: Equivalent to error diagnostic level. Some examples:

    +
      +
    • A future-incompatible or edition-based lint that has graduated from the +warning level.
    • +
    • Something that has an extremely high confidence that is incorrect, but +still want an escape hatch to allow it to pass.
    • +
    +
  • +
  • +

    warn: Equivalent to the warning diagnostic level. See warning above +for guidelines.

    +
  • +
  • +

    allow: Examples of the kinds of lints that should default to allow:

    +
      +
    • The lint has a too high false positive rate.
    • +
    • The lint is too opinionated.
    • +
    • The lint is experimental.
    • +
    • The lint is used for enforcing something that is not normally enforced. +For example, the unsafe_code lint can be used to prevent usage of unsafe +code.
    • +
    +
  • +
+

More information about lint levels can be found in the rustc +book and the reference.

+

Helpful tips and options

+

Finding the source of errors

+

There are three main ways to find where a given error is emitted:

+
    +
  • +

    grep for either a sub-part of the error message/label or error code. This +usually works well and is straightforward, but there are some cases where +the code emitting the error is removed from the code where the error is +constructed behind a relatively deep call-stack. Even then, it is a good way +to get your bearings.

    +
  • +
  • +

    Invoking rustc with the nightly-only flag -Z treat-err-as-bug=1 +will treat the first error being emitted as an Internal Compiler Error, which +allows you to get a +stack trace at the point the error has been emitted. Change the 1 to +something else if you wish to trigger on a later error.

    +

    There are limitations with this approach:

    +
      +
    • Some calls get elided from the stack trace because they get inlined in the compiled rustc.
    • +
    • The construction of the error is far away from where it is emitted, +a problem similar to the one we faced with the grep approach. +In some cases, we buffer multiple errors in order to emit them in order.
    • +
    +
  • +
  • +

    Invoking rustc with -Z track-diagnostics will print error creation +locations alongside the error.

    +
  • +
+

The regular development practices apply: judicious use of debug!() statements +and use of a debugger to trigger break points in order to figure out in what +order things are happening.

+

Span

+

Span is the primary data structure in rustc used to represent a +location in the code being compiled. Spans are attached to most constructs in +HIR and MIR, allowing for more informative error reporting.

+

A Span can be looked up in a SourceMap to get a "snippet" +useful for displaying errors with span_to_snippet and other +similar methods on the SourceMap.

+

Error messages

+

The rustc_errors crate defines most of the utilities used for +reporting errors.

+

Diagnostics can be implemented as types which implement the Diagnostic +trait. This is preferred for new diagnostics as it enforces a separation +between diagnostic emitting logic and the main code paths. For less-complex +diagnostics, the Diagnostic trait can be derived -- see Diagnostic +structs. Within the trait implementation, the APIs +described below can be used as normal.

+

DiagCtxt has methods that create and emit errors. These methods +usually have names like span_err or struct_span_err or span_warn, etc... +There are lots of them; they emit different types of "errors", such as +warnings, errors, fatal errors, suggestions, etc.

+

In general, there are two classes of such methods: ones that emit an error +directly and ones that allow finer control over what to emit. For example, +span_err emits the given error message at the given Span, but +struct_span_err instead returns a +Diag.

+

Most of these methods will accept strings, but it is recommended that typed +identifiers for translatable diagnostics be used for new diagnostics (see +Translation).

+

Diag allows you to add related notes and suggestions to an error +before emitting it by calling the emit method. (Failing to either +emit or cancel a Diag will result in an ICE.) See the +docs for more info on what you can do.

+
// Get a `Diag`. This does _not_ emit an error yet.
+let mut err = sess.dcx.struct_span_err(sp, fluent::example::example_error);
+
+// In some cases, you might need to check if `sp` is generated by a macro to
+// avoid printing weird errors about macro-generated code.
+
+if let Ok(snippet) = sess.source_map().span_to_snippet(sp) {
+    // Use the snippet to generate a suggested fix
+    err.span_suggestion(suggestion_sp, fluent::example::try_qux_suggestion, format!("qux {}", snippet));
+} else {
+    // If we weren't able to generate a snippet, then emit a "help" message
+    // instead of a concrete "suggestion". In practice this is unlikely to be
+    // reached.
+    err.span_help(suggestion_sp, fluent::example::qux_suggestion);
+}
+
+// emit the error
+err.emit();
+
+
example-example-error = oh no! this is an error!
+  .try-qux-suggestion = try using a qux here
+  .qux-suggestion = you could use a qux here instead
+
+

Suggestions

+

In addition to telling the user exactly why their code is wrong, it's +oftentimes furthermore possible to tell them how to fix it. To this end, +Diag offers a structured suggestions API, which formats code +suggestions pleasingly in the terminal, or (when the --error-format json flag +is passed) as JSON for consumption by tools like rustfix.

+

Not all suggestions should be applied mechanically, they have a degree of +confidence in the suggested code, from high +(Applicability::MachineApplicable) to low (Applicability::MaybeIncorrect). +Be conservative when choosing the level. Use the +span_suggestion method of Diag to +make a suggestion. The last argument provides a hint to tools whether +the suggestion is mechanically applicable or not.

+

Suggestions point to one or more spans with corresponding code that will +replace their current content.

+

The message that accompanies them should be understandable in the following +contexts:

+
    +
  • shown as an independent sub-diagnostic (this is the default output)
  • +
  • shown as a label pointing at the affected span (this is done automatically if +some heuristics for verbosity are met)
  • +
  • shown as a help sub-diagnostic with no content (used for cases where the +suggestion is obvious from the text, but we still want to let tools to apply +them))
  • +
  • not shown (used for very obvious cases, but we still want to allow tools to +apply them)
  • +
+

For example, to make our qux suggestion machine-applicable, we would do:

+
let mut err = sess.dcx.struct_span_err(sp, fluent::example::message);
+
+if let Ok(snippet) = sess.source_map().span_to_snippet(sp) {
+    err.span_suggestion(
+        suggestion_sp,
+        fluent::example::try_qux_suggestion,
+        format!("qux {}", snippet),
+        Applicability::MachineApplicable,
+    );
+} else {
+    err.span_help(suggestion_sp, fluent::example::qux_suggestion);
+}
+
+err.emit();
+
+

This might emit an error like

+
$ rustc mycode.rs
+error[E0999]: oh no! this is an error!
+ --> mycode.rs:3:5
+  |
+3 |     sad()
+  |     ^ help: try using a qux here: `qux sad()`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0999`.
+
+

In some cases, like when the suggestion spans multiple lines or when there are +multiple suggestions, the suggestions are displayed on their own:

+
error[E0999]: oh no! this is an error!
+ --> mycode.rs:3:5
+  |
+3 |     sad()
+  |     ^
+help: try using a qux here:
+  |
+3 |     qux sad()
+  |     ^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0999`.
+
+

The possible values of Applicability are:

+
    +
  • MachineApplicable: Can be applied mechanically.
  • +
  • HasPlaceholders: Cannot be applied mechanically because it has placeholder +text in the suggestions. For example: try adding a type: `let x: <type>` .
  • +
  • MaybeIncorrect: Cannot be applied mechanically because the suggestion may +or may not be a good one.
  • +
  • Unspecified: Cannot be applied mechanically because we don't know which +of the above cases it falls into.
  • +
+

Suggestion Style Guide

+
    +
  • +

    Suggestions should not be a question. In particular, language like "did you +mean" should be avoided. Sometimes, it's unclear why a particular suggestion +is being made. In these cases, it's better to be upfront about what the +suggestion is.

    +

    Compare "did you mean: Foo" vs. "there is a struct with a similar name: Foo".

    +
  • +
  • +

    The message should not contain any phrases like "the following", "as shown", +etc. Use the span to convey what is being talked about.

    +
  • +
  • +

    The message may contain further instruction such as "to do xyz, use" or "to do +xyz, use abc".

    +
  • +
  • +

    The message may contain a name of a function, variable, or type, but avoid +whole expressions.

    +
  • +
+

Lints

+

The compiler linting infrastructure is defined in the rustc_middle::lint +module.

+

When do lints run?

+

Different lints will run at different times based on what information the lint +needs to do its job. Some lints get grouped into passes where the lints +within a pass are processed together via a single visitor. Some of the passes +are:

+
    +
  • +

    Pre-expansion pass: Works on AST nodes before macro expansion. This +should generally be avoided.

    +
      +
    • Example: keyword_idents checks for identifiers that will become +keywords in future editions, but is sensitive to identifiers used in +macros.
    • +
    +
  • +
  • +

    Early lint pass: Works on AST nodes after macro expansion and name +resolution, just before AST lowering. These lints are for purely +syntactical lints.

    +
      +
    • Example: The unused_parens lint checks for parenthesized-expressions +in situations where they are not needed, like an if condition.
    • +
    +
  • +
  • +

    Late lint pass: Works on HIR nodes, towards the end of analysis (after +borrow checking, etc.). These lints have full type information available. +Most lints are late.

    +
      +
    • Example: The invalid_value lint (which checks for obviously invalid +uninitialized values) is a late lint because it needs type information to +figure out whether a type allows being left uninitialized.
    • +
    +
  • +
  • +

    MIR pass: Works on MIR nodes. This isn't quite the same as other passes; +lints that work on MIR nodes have their own methods for running.

    +
      +
    • Example: The arithmetic_overflow lint is emitted when it detects a +constant value that may overflow.
    • +
    +
  • +
+

Most lints work well via the pass systems, and they have a fairly +straightforward interface and easy way to integrate (mostly just implementing +a specific check function). However, some lints are easier to write when +they live on a specific code path anywhere in the compiler. For example, the +unused_mut lint is implemented in the borrow checker as it requires some +information and state in the borrow checker.

+

Some of these inline lints fire before the linting system is ready. Those +lints will be buffered where they are held until later phases of the +compiler when the linting system is ready. See Linting early in the +compiler.

+

Lint definition terms

+

Lints are managed via the LintStore and get registered in +various ways. The following terms refer to the different classes of lints +generally based on how they are registered.

+
    +
  • Built-in lints are defined inside the compiler source.
  • +
  • Driver-registered lints are registered when the compiler driver is created +by an external driver. This is the mechanism used by Clippy, for example.
  • +
  • Tool lints are lints with a path prefix like clippy:: or rustdoc::.
  • +
  • Internal lints are the rustc:: scoped tool lints that only run on the +rustc source tree itself and are defined in the compiler source like a +regular built-in lint.
  • +
+

More information about lint registration can be found in the LintStore +chapter.

+

Declaring a lint

+

The built-in compiler lints are defined in the rustc_lint +crate. Lints that need to be implemented in other crates are defined in +rustc_lint_defs. You should prefer to place lints in rustc_lint if +possible. One benefit is that it is close to the dependency root, so it can be +much faster to work on.

+

Every lint is implemented via a struct that implements the LintPass trait +(you can also implement one of the more specific lint pass traits, either +EarlyLintPass or LateLintPass depending on when is best for your lint to run). +The trait implementation allows you to check certain syntactic constructs +as the linter walks the AST. You can then choose to emit lints in a +very similar way to compile errors.

+

You also declare the metadata of a particular lint via the declare_lint! +macro. This includes the name, the default level, a short description, and some +more details.

+

Note that the lint and the lint pass must be registered with the compiler.

+

For example, the following lint checks for uses +of while true { ... } and suggests using loop { ... } instead.

+
// Declare a lint called `WHILE_TRUE`
+declare_lint! {
+    WHILE_TRUE,
+
+    // warn-by-default
+    Warn,
+
+    // This string is the lint description
+    "suggest using `loop { }` instead of `while true { }`"
+}
+
+// This declares a struct and a lint pass, providing a list of associated lints. The
+// compiler currently doesn't use the associated lints directly (e.g., to not
+// run the pass or otherwise check that the pass emits the appropriate set of
+// lints). However, it's good to be accurate here as it's possible that we're
+// going to register the lints via the get_lints method on our lint pass (that
+// this macro generates).
+declare_lint_pass!(WhileTrue => [WHILE_TRUE]);
+
+// Helper function for `WhileTrue` lint.
+// Traverse through any amount of parenthesis and return the first non-parens expression.
+fn pierce_parens(mut expr: &ast::Expr) -> &ast::Expr {
+    while let ast::ExprKind::Paren(sub) = &expr.kind {
+        expr = sub;
+    }
+    expr
+}
+
+// `EarlyLintPass` has lots of methods. We only override the definition of
+// `check_expr` for this lint because that's all we need, but you could
+// override other methods for your own lint. See the rustc docs for a full
+// list of methods.
+impl EarlyLintPass for WhileTrue {
+    fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
+        if let ast::ExprKind::While(cond, ..) = &e.kind
+            && let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind
+            && let ast::LitKind::Bool(true) = lit.kind
+            && !lit.span.from_expansion()
+        {
+            let condition_span = cx.sess.source_map().guess_head_span(e.span);
+            cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
+                lint.build(fluent::example::use_loop)
+                    .span_suggestion_short(
+                        condition_span,
+                        fluent::example::suggestion,
+                        "loop".to_owned(),
+                        Applicability::MachineApplicable,
+                    )
+                    .emit();
+            })
+        }
+    }
+}
+
+
example-use-loop = denote infinite loops with `loop {"{"} ... {"}"}`
+  .suggestion = use `loop`
+
+

Edition-gated lints

+

Sometimes we want to change the behavior of a lint in a new edition. To do this, +we just add the transition to our invocation of declare_lint!:

+
declare_lint! {
+    pub ANONYMOUS_PARAMETERS,
+    Allow,
+    "detects anonymous parameters",
+    Edition::Edition2018 => Warn,
+}
+
+

This makes the ANONYMOUS_PARAMETERS lint allow-by-default in the 2015 edition +but warn-by-default in the 2018 edition.

+

See Edition-specific lints for more information.

+

Feature-gated lints

+

Lints belonging to a feature should only be usable if the feature is enabled in the +crate. To support this, lint declarations can contain a feature gate like so:

+
declare_lint! {
+    pub SOME_LINT_NAME,
+    Warn,
+    "a new and useful, but feature gated lint",
+    @feature_gate = sym::feature_name;
+}
+
+

Future-incompatible lints

+

The use of the term future-incompatible within the compiler has a slightly +broader meaning than what rustc exposes to users of the compiler.

+

Inside rustc, future-incompatible lints are for signalling to the user that code they have +written may not compile in the future. In general, future-incompatible code +exists for two reasons:

+
    +
  • The user has written unsound code that the compiler mistakenly accepted. While +it is within Rust's backwards compatibility guarantees to fix the soundness hole +(breaking the user's code), the lint is there to warn the user that this will happen +in some upcoming version of rustc regardless of which edition the code uses. This is the +meaning that rustc exclusively exposes to users as "future incompatible".
  • +
  • The user has written code that will either no longer compiler or will change +meaning in an upcoming edition. These are often called "edition lints" and can be +typically seen in the various "edition compatibility" lint groups (e.g., rust_2021_compatibility) +that are used to lint against code that will break if the user updates the crate's edition. +See migration lints for more details.
  • +
+

A future-incompatible lint should be declared with the @future_incompatible +additional "field":

+
declare_lint! {
+    pub ANONYMOUS_PARAMETERS,
+    Allow,
+    "detects anonymous parameters",
+    @future_incompatible = FutureIncompatibleInfo {
+        reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",
+        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
+    };
+}
+
+

Notice the reason field which describes why the future incompatible change is happening. +This will change the diagnostic message the user receives as well as determine which +lint groups the lint is added to. In the example above, the lint is an "edition lint" +(since its "reason" is EditionError), signifying to the user that the use of anonymous +parameters will no longer compile in Rust 2018 and beyond.

+

Inside LintStore::register_lints, lints with future_incompatible +fields get placed into either edition-based lint groups (if their reason is tied to +an edition) or into the future_incompatibility lint group.

+

If you need a combination of options that's not supported by the +declare_lint! macro, you can always change the declare_lint! macro +to support this.

+

Renaming or removing a lint

+

If it is determined that a lint is either improperly named or no longer needed, +the lint must be registered for renaming or removal, which will trigger a warning if a user tries +to use the old lint name. To declare a rename/remove, add a line with +store.register_renamed or store.register_removed to the code of the +rustc_lint::register_builtins function.

+
store.register_renamed("single_use_lifetime", "single_use_lifetimes");
+
+

Lint Groups

+

Lints can be turned on in groups. These groups are declared in the +register_builtins function in rustc_lint::lib. The +add_lint_group! macro is used to declare a new group.

+

For example,

+
add_lint_group!(sess,
+    "nonstandard_style",
+    NON_CAMEL_CASE_TYPES,
+    NON_SNAKE_CASE,
+    NON_UPPER_CASE_GLOBALS);
+
+

This defines the nonstandard_style group which turns on the listed lints. A +user can turn on these lints with a !#[warn(nonstandard_style)] attribute in +the source code, or by passing -W nonstandard-style on the command line.

+

Some lint groups are created automatically in LintStore::register_lints. For instance, +any lint declared with FutureIncompatibleInfo where the reason is +FutureIncompatibilityReason::FutureReleaseError (the default when +@future_incompatible is used in declare_lint!), will be added to +the future_incompatible lint group. Editions also have their own lint groups +(e.g., rust_2021_compatibility) automatically generated for any lints signaling +future-incompatible code that will break in the specified edition.

+

Linting early in the compiler

+

On occasion, you may need to define a lint that runs before the linting system +has been initialized (e.g. during parsing or macro expansion). This is +problematic because we need to have computed lint levels to know whether we +should emit a warning or an error or nothing at all.

+

To solve this problem, we buffer the lints until the linting system is +processed. Session and ParseSess both have +buffer_lint methods that allow you to buffer a lint for later. The linting +system automatically takes care of handling buffered lints later.

+

Thus, to define a lint that runs early in the compilation, one defines a lint +like normal but invokes the lint with buffer_lint.

+

Linting even earlier in the compiler

+

The parser (rustc_ast) is interesting in that it cannot have dependencies on +any of the other rustc* crates. In particular, it cannot depend on +rustc_middle::lint or rustc_lint, where all of the compiler linting +infrastructure is defined. That's troublesome!

+

To solve this, rustc_ast defines its own buffered lint type, which +ParseSess::buffer_lint uses. After macro expansion, these buffered lints are +then dumped into the Session::buffered_lints used by the rest of the compiler.

+

JSON diagnostic output

+

The compiler accepts an --error-format json flag to output +diagnostics as JSON objects (for the benefit of tools such as cargo fix). It looks like this:

+
$ rustc json_error_demo.rs --error-format json
+{"message":"cannot add `&str` to `{integer}`","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"json_error_demo.rs","byte_start":50,"byte_end":51,"line_start":4,"line_end":4,"column_start":7,"column_end":8,"is_primary":true,"text":[{"text":"    a + b","highlight_start":7,"highlight_end":8}],"label":"no implementation for `{integer} + &str`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the trait `std::ops::Add<&str>` is not implemented for `{integer}`","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: cannot add `&str` to `{integer}`\n --> json_error_demo.rs:4:7\n  |\n4 |     a + b\n  |       ^ no implementation for `{integer} + &str`\n  |\n  = help: the trait `std::ops::Add<&str>` is not implemented for `{integer}`\n\n"}
+{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
+{"message":"For more information about this error, try `rustc --explain E0277`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0277`.\n"}
+
+

Note that the output is a series of lines, each of which is a JSON +object, but the series of lines taken together is, unfortunately, not +valid JSON, thwarting tools and tricks (such as piping to python3 -m json.tool) +that require such. (One speculates that this was intentional for LSP +performance purposes, so that each line/object can be sent as +it is flushed?)

+

Also note the "rendered" field, which contains the "human" output as a +string; this was introduced so that UI tests could both make use of +the structured JSON and see the "human" output (well, sans colors) +without having to compile everything twice.

+

The "human" readable and the json format emitter can be found under +rustc_errors, both were moved from the rustc_ast crate to the +rustc_errors crate.

+

The JSON emitter defines its own Diagnostic +struct +(and sub-structs) for the JSON serialization. Don't confuse this with +errors::Diag!

+

#[rustc_on_unimplemented(...)]

+

The #[rustc_on_unimplemented] attribute allows trait definitions to add specialized +notes to error messages when an implementation was expected but not found. +You can refer to the trait's generic arguments by name and to the resolved type using Self.

+

For example:

+
#![feature(rustc_attrs)]
+
+#[rustc_on_unimplemented="an iterator over elements of type `{A}` \
+    cannot be built from a collection of type `{Self}`"]
+trait MyIterator<A> {
+    fn next(&mut self) -> A;
+}
+
+fn iterate_chars<I: MyIterator<char>>(i: I) {
+    // ...
+}
+
+fn main() {
+    iterate_chars(&[1, 2, 3][..]);
+}
+
+

When the user compiles this, they will see the following;

+
error[E0277]: the trait bound `&[{integer}]: MyIterator<char>` is not satisfied
+  --> <anon>:14:5
+   |
+14 |     iterate_chars(&[1, 2, 3][..]);
+   |     ^^^^^^^^^^^^^ an iterator over elements of type `char` cannot be built from a collection of type `&[{integer}]`
+   |
+   = help: the trait `MyIterator<char>` is not implemented for `&[{integer}]`
+   = note: required by `iterate_chars`
+
+

rustc_on_unimplemented also supports advanced filtering for better targeting +of messages, as well as modifying specific parts of the error message. You +target the text of:

+
    +
  • the main error message (message)
  • +
  • the label (label)
  • +
  • an extra note (note)
  • +
+

For example, the following attribute

+
#[rustc_on_unimplemented(
+    message="message",
+    label="label",
+    note="note"
+)]
+trait MyIterator<A> {
+    fn next(&mut self) -> A;
+}
+
+

Would generate the following output:

+
error[E0277]: message
+  --> <anon>:14:5
+   |
+14 |     iterate_chars(&[1, 2, 3][..]);
+   |     ^^^^^^^^^^^^^ label
+   |
+   = note: note
+   = help: the trait `MyIterator<char>` is not implemented for `&[{integer}]`
+   = note: required by `iterate_chars`
+
+

To allow more targeted error messages, it is possible to filter the +application of these fields based on a variety of attributes when using +on:

+
    +
  • crate_local: whether the code causing the trait bound to not be +fulfilled is part of the user's crate. This is used to avoid suggesting +code changes that would require modifying a dependency.
  • +
  • Any of the generic arguments that can be substituted in the text can be +referred by name as well for filtering, like Rhs="i32", except for +Self.
  • +
  • _Self: to filter only on a particular calculated trait resolution, like +Self="std::iter::Iterator<char>". This is needed because Self is a +keyword which cannot appear in attributes.
  • +
  • direct: user-specified rather than derived obligation.
  • +
  • from_method: usable both as boolean (whether the flag is present, like +crate_local) or matching against a particular method. Currently used +for try.
  • +
  • from_desugaring: usable both as boolean (whether the flag is present) +or matching against a particular desugaring. The desugaring is identified +with its variant name in the DesugaringKind enum.
  • +
+

For example, the Iterator trait can be annotated in the following way:

+
#[rustc_on_unimplemented(
+    on(
+        _Self="&str",
+        note="call `.chars()` or `.as_bytes()` on `{Self}`"
+    ),
+    message="`{Self}` is not an iterator",
+    label="`{Self}` is not an iterator",
+    note="maybe try calling `.iter()` or a similar method"
+)]
+pub trait Iterator {}
+
+

Which would produce the following outputs:

+
error[E0277]: `Foo` is not an iterator
+ --> src/main.rs:4:16
+  |
+4 |     for foo in Foo {}
+  |                ^^^ `Foo` is not an iterator
+  |
+  = note: maybe try calling `.iter()` or a similar method
+  = help: the trait `std::iter::Iterator` is not implemented for `Foo`
+  = note: required by `std::iter::IntoIterator::into_iter`
+
+error[E0277]: `&str` is not an iterator
+ --> src/main.rs:5:16
+  |
+5 |     for foo in "" {}
+  |                ^^ `&str` is not an iterator
+  |
+  = note: call `.chars()` or `.bytes() on `&str`
+  = help: the trait `std::iter::Iterator` is not implemented for `&str`
+  = note: required by `std::iter::IntoIterator::into_iter`
+
+

If you need to filter on multiple attributes, you can use all, any or +not in the following way:

+
#[rustc_on_unimplemented(
+    on(
+        all(_Self="&str", T="std::string::String"),
+        note="you can coerce a `{T}` into a `{Self}` by writing `&*variable`"
+    )
+)]
+pub trait From<T>: Sized { /* ... */ }
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/diagnostics/diagnostic-codes.html b/diagnostics/diagnostic-codes.html new file mode 100644 index 000000000..dd75af5b0 --- /dev/null +++ b/diagnostics/diagnostic-codes.html @@ -0,0 +1,12 @@ + + + + + Redirecting... + + + + +

Redirecting to... error-codes.html.

+ + diff --git a/diagnostics/diagnostic-items.html b/diagnostics/diagnostic-items.html new file mode 100644 index 000000000..69fc39426 --- /dev/null +++ b/diagnostics/diagnostic-items.html @@ -0,0 +1,340 @@ + + + + + + Diagnostic items - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Diagnostic Items

+

While writing lints it's common to check for specific types, traits and +functions. This raises the question on how to check for these. Types can be +checked by their complete type path. However, this requires hard coding paths +and can lead to misclassifications in some edge cases. To counteract this, +rustc has introduced diagnostic items that are used to identify types via +Symbols.

+

Finding diagnostic items

+

Diagnostic items are added to items inside rustc/std/core/alloc with the +rustc_diagnostic_item attribute. The item for a specific type can be found by +opening the source code in the documentation and looking for this attribute. +Note that it's often added with the cfg_attr attribute to avoid compilation +errors during tests. A definition often looks like this:

+
// This is the diagnostic item for this type   vvvvvvv
+#[cfg_attr(not(test), rustc_diagnostic_item = "Penguin")]
+struct Penguin;
+
+

Diagnostic items are usually only added to traits, +types, +and standalone functions. +If the goal is to check for an associated type or method, +please use the diagnostic item of the item and reference +Using Diagnostic Items.

+

Adding diagnostic items

+

A new diagnostic item can be added with these two steps:

+
    +
  1. +

    Find the target item inside the Rust repo. Now add the diagnostic item as a +string via the rustc_diagnostic_item attribute. This can sometimes cause +compilation errors while running tests. These errors can be avoided by using +the cfg_attr attribute with the not(test) condition (it's fine adding +then for all rustc_diagnostic_item attributes as a preventive manner). At +the end, it should look like this:

    +
    // This will be the new diagnostic item        vvv
    +#[cfg_attr(not(test), rustc_diagnostic_item = "Cat")]
    +struct Cat;
    +
    +

    For the naming conventions of diagnostic items, please refer to +Naming Conventions.

    +
  2. +
  3. +

    Diagnostic items in code are accessed via symbols in +rustc_span::symbol::sym. +To add your newly-created diagnostic item, +simply open the module file, +and add the name (In this case Cat) at the correct point in the list.

    +
  4. +
+

Now you can create a pull request with your changes. :tada:

+
+

NOTE: +When using diagnostic items in other projects like Clippy, +it might take some time until the repos get synchronized.

+
+

Naming conventions

+

Diagnostic items don't have a naming convention yet. +Following are some guidelines that should be used in future, +but might differ from existing names:

+
    +
  • Types, traits, and enums are named using UpperCamelCase +(Examples: Iterator and HashMap)
  • +
  • For type names that are used multiple times, +like Writer, +it's good to choose a more precise name, +maybe by adding the module to it +(Example: IoWriter)
  • +
  • Associated items should not get their own diagnostic items, +but instead be accessed indirectly by the diagnostic item +of the type they're originating from.
  • +
  • Freestanding functions like std::mem::swap() should be named using +snake_case with one important (export) module as a prefix +(Examples: mem_swap and cmp_max)
  • +
  • Modules should usually not have a diagnostic item attached to them. +Diagnostic items were added to avoid the usage of paths, +and using them on modules would therefore most likely be counterproductive.
  • +
+

Using diagnostic items

+

In rustc, diagnostic items are looked up via Symbols from inside the +rustc_span::symbol::sym module. These can then be mapped to DefIds +using TyCtxt::get_diagnostic_item() or checked if they match a DefId +using TyCtxt::is_diagnostic_item(). When mapping from a diagnostic item to +a DefId, the method will return a Option<DefId>. This can be None if +either the symbol isn't a diagnostic item or the type is not registered, for +instance when compiling with #[no_std]. +All the following examples are based on DefIds and their usage.

+

Example: Checking for a type

+
#![allow(unused)]
+fn main() {
+use rustc_span::symbol::sym;
+
+/// This example checks if the given type (`ty`) has the type `HashMap` using
+/// `TyCtxt::is_diagnostic_item()`
+fn example_1(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
+    match ty.kind() {
+        ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::HashMap, adt.did()),
+        _ => false,
+    }
+}
+}
+
+

Example: Checking for a trait implementation

+
#![allow(unused)]
+fn main() {
+/// This example checks if a given [`DefId`] from a method is part of a trait
+/// implementation defined by a diagnostic item.
+fn is_diag_trait_item(
+    cx: &LateContext<'_>,
+    def_id: DefId,
+    diag_item: Symbol
+) -> bool {
+    if let Some(trait_did) = cx.tcx.trait_of_item(def_id) {
+        return cx.tcx.is_diagnostic_item(diag_item, trait_did);
+    }
+    false
+}
+}
+
+

Associated Types

+

Associated types of diagnostic items can be accessed indirectly by first +getting the DefId of the trait and then calling +TyCtxt::associated_items(). This returns an AssocItems object which can +be used for further checks. Checkout +clippy_utils::ty::get_iterator_item_ty() for an example usage of this.

+

Usage in Clippy

+

Clippy tries to use diagnostic items where possible and has developed some +wrapper and utility functions. Please also refer to its documentation when +using diagnostic items in Clippy. (See Common tools for writing +lints.)

+ +

These are probably only interesting to people +who really want to take a deep dive into the topic :)

+
    +
  • rust#60966: The Rust PR that introduced diagnostic items
  • +
  • rust-clippy#5393: Clippy's tracking issue for moving away from hard coded paths to +diagnostic item
  • +
+ + +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/diagnostics/diagnostic-structs.html b/diagnostics/diagnostic-structs.html new file mode 100644 index 000000000..1ef0ceced --- /dev/null +++ b/diagnostics/diagnostic-structs.html @@ -0,0 +1,655 @@ + + + + + + Diagnostic and subdiagnostic structs - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Diagnostic and subdiagnostic structs

+

rustc has three diagnostic traits that can be used to create diagnostics: +Diagnostic, LintDiagnostic, and Subdiagnostic. For simple diagnostics, +instead of using the Diag API to create and emit diagnostics, +derived impls can be used. They are only suitable for simple diagnostics that +don't require much logic in deciding whether or not to add additional +subdiagnostics.

+

Such diagnostic can be translated into +different languages and each has a slug that uniquely identifies the +diagnostic.

+

#[derive(Diagnostic)] and #[derive(LintDiagnostic)]

+

Consider the definition of the "field already declared" diagnostic +shown below:

+
#[derive(Diagnostic)]
+#[diag(hir_analysis_field_already_declared, code = E0124)]
+pub struct FieldAlreadyDeclared {
+    pub field_name: Ident,
+    #[primary_span]
+    #[label]
+    pub span: Span,
+    #[label(previous_decl_label)]
+    pub prev_span: Span,
+}
+
+

Diagnostic can only be derived on structs and enums. +Attributes that are placed on the type for structs are placed on each +variants for enums (or vice versa). Each Diagnostic has to have one +attribute, #[diag(...)], applied to the struct or each enum variant.

+

If an error has an error code (e.g. "E0624"), then that can be specified using +the code sub-attribute. Specifying a code isn't mandatory, but if you are +porting a diagnostic that uses Diag to use Diagnostic +then you should keep the code if there was one.

+

#[diag(..)] must provide a slug as the first positional argument (a path to an +item in rustc_errors::fluent::*). A slug uniquely identifies the diagnostic +and is also how the compiler knows what error message to emit (in the default +locale of the compiler, or in the locale requested by the user). See +translation documentation to learn more about how +translatable error messages are written and how slug items are generated.

+

In our example, the Fluent message for the "field already declared" diagnostic +looks like this:

+
hir_analysis_field_already_declared =
+    field `{$field_name}` is already declared
+    .label = field already declared
+    .previous_decl_label = `{$field_name}` first declared here
+
+

hir_analysis_field_already_declared is the slug from our example and is followed +by the diagnostic message.

+

Every field of the Diagnostic which does not have an annotation is +available in Fluent messages as a variable, like field_name in the example +above. Fields can be annotated #[skip_arg] if this is undesired.

+

Using the #[primary_span] attribute on a field (that has type Span) +indicates the primary span of the diagnostic which will have the main message +of the diagnostic.

+

Diagnostics are more than just their primary message, they often include +labels, notes, help messages and suggestions, all of which can also be +specified on a Diagnostic.

+

#[label], #[help], #[warning] and #[note] can all be applied to fields which have the +type Span. Applying any of these attributes will create the corresponding +subdiagnostic with that Span. These attributes will look for their +diagnostic message in a Fluent attribute attached to the primary Fluent +message. In our example, #[label] will look for +hir_analysis_field_already_declared.label (which has the message "field already +declared"). If there is more than one subdiagnostic of the same type, then +these attributes can also take a value that is the attribute name to look for +(e.g. previous_decl_label in our example).

+

Other types have special behavior when used in a Diagnostic derive:

+
    +
  • Any attribute applied to an Option<T> will only emit a +subdiagnostic if the option is Some(..).
  • +
  • Any attribute applied to a Vec<T> will be repeated for each element of the +vector.
  • +
+

#[help], #[warning] and #[note] can also be applied to the struct itself, in which case +they work exactly like when applied to fields except the subdiagnostic won't +have a Span. These attributes can also be applied to fields of type () for +the same effect, which when combined with the Option type can be used to +represent optional #[note]/#[help]/#[warning] subdiagnostics.

+

Suggestions can be emitted using one of four field attributes:

+
    +
  • #[suggestion(slug, code = "...", applicability = "...")]
  • +
  • #[suggestion_hidden(slug, code = "...", applicability = "...")]
  • +
  • #[suggestion_short(slug, code = "...", applicability = "...")]
  • +
  • #[suggestion_verbose(slug, code = "...", applicability = "...")]
  • +
+

Suggestions must be applied on either a Span field or a (Span, MachineApplicability) field. Similarly to other field attributes, the slug +specifies the Fluent attribute with the message and defaults to the equivalent +of .suggestion. code specifies the code that should be suggested as a +replacement and is a format string (e.g. {field_name} would be replaced by +the value of the field_name field of the struct), not a Fluent identifier. +applicability can be used to specify the applicability in the attribute, it +cannot be used when the field's type contains an Applicability.

+

In the end, the Diagnostic derive will generate an implementation of +Diagnostic that looks like the following:

+
impl<'a, G: EmissionGuarantee> Diagnostic<'a> for FieldAlreadyDeclared {
+    fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
+        let mut diag = Diag::new(dcx, level, fluent::hir_analysis_field_already_declared);
+        diag.set_span(self.span);
+        diag.span_label(
+            self.span,
+            fluent::hir_analysis_label
+        );
+        diag.span_label(
+            self.prev_span,
+            fluent::hir_analysis_previous_decl_label
+        );
+        diag
+    }
+}
+
+

Now that we've defined our diagnostic, how do we use it? It's quite +straightforward, just create an instance of the struct and pass it to +emit_err (or emit_warning):

+
tcx.dcx().emit_err(FieldAlreadyDeclared {
+    field_name: f.ident,
+    span: f.span,
+    prev_span,
+});
+
+

Reference

+

#[derive(Diagnostic)] and #[derive(LintDiagnostic)] support the +following attributes:

+
    +
  • #[diag(slug, code = "...")] +
      +
    • Applied to struct or enum variant.
    • +
    • Mandatory
    • +
    • Defines the text and error code to be associated with the diagnostic.
    • +
    • Slug (Mandatory) +
        +
      • Uniquely identifies the diagnostic and corresponds to its Fluent message, +mandatory.
      • +
      • A path to an item in rustc_errors::fluent, e.g. +rustc_errors::fluent::hir_analysis_field_already_declared +(rustc_errors::fluent is implicit in the attribute, so just +hir_analysis_field_already_declared).
      • +
      • See translation documentation.
      • +
      +
    • +
    • code = "..." (Optional) +
        +
      • Specifies the error code.
      • +
      +
    • +
    +
  • +
  • #[note] or #[note(slug)] (Optional) +
      +
    • Applied to struct or struct fields of type Span, Option<()> or ().
    • +
    • Adds a note subdiagnostic.
    • +
    • Value is a path to an item in rustc_errors::fluent for the note's +message. +
        +
      • Defaults to equivalent of .note.
      • +
      +
    • +
    • If applied to a Span field, creates a spanned note.
    • +
    +
  • +
  • #[help] or #[help(slug)] (Optional) +
      +
    • Applied to struct or struct fields of type Span, Option<()> or ().
    • +
    • Adds a help subdiagnostic.
    • +
    • Value is a path to an item in rustc_errors::fluent for the note's +message. +
        +
      • Defaults to equivalent of .help.
      • +
      +
    • +
    • If applied to a Span field, creates a spanned help.
    • +
    +
  • +
  • #[label] or #[label(slug)] (Optional) +
      +
    • Applied to Span fields.
    • +
    • Adds a label subdiagnostic.
    • +
    • Value is a path to an item in rustc_errors::fluent for the note's +message. +
        +
      • Defaults to equivalent of .label.
      • +
      +
    • +
    +
  • +
  • #[warning] or #[warning(slug)] (Optional) +
      +
    • Applied to struct or struct fields of type Span, Option<()> or ().
    • +
    • Adds a warning subdiagnostic.
    • +
    • Value is a path to an item in rustc_errors::fluent for the note's +message. +
        +
      • Defaults to equivalent of .warn.
      • +
      +
    • +
    +
  • +
  • #[suggestion{,_hidden,_short,_verbose}(slug, code = "...", applicability = "...")] +(Optional) +
      +
    • Applied to (Span, MachineApplicability) or Span fields.
    • +
    • Adds a suggestion subdiagnostic.
    • +
    • Slug (Mandatory) +
        +
      • A path to an item in rustc_errors::fluent, e.g. +rustc_errors::fluent::hir_analysis_field_already_declared +(rustc_errors::fluent is implicit in the attribute, so just +hir_analysis_field_already_declared). Fluent attributes for all messages +exist as top-level items in that module (so hir_analysis_message.attr is just +attr).
      • +
      • See translation documentation.
      • +
      • Defaults to rustc_errors::fluent::_subdiag::suggestion (or
      • +
      • .suggestion in Fluent).
      • +
      +
    • +
    • code = "..."/code("...", ...) (Mandatory) +
        +
      • One or multiple format strings indicating the code to be suggested as a +replacement. Multiple values signify multiple possible replacements.
      • +
      +
    • +
    • applicability = "..." (Optional) +
        +
      • String which must be one of machine-applicable, maybe-incorrect, +has-placeholders or unspecified.
      • +
      +
    • +
    +
  • +
  • #[subdiagnostic] +
      +
    • Applied to a type that implements Subdiagnostic (from +#[derive(Subdiagnostic)]).
    • +
    • Adds the subdiagnostic represented by the subdiagnostic struct.
    • +
    +
  • +
  • #[primary_span] (Optional) +
      +
    • Applied to Span fields on Subdiagnostics. Not used for LintDiagnostics.
    • +
    • Indicates the primary span of the diagnostic.
    • +
    +
  • +
  • #[skip_arg] (Optional) +
      +
    • Applied to any field.
    • +
    • Prevents the field from being provided as a diagnostic argument.
    • +
    +
  • +
+

#[derive(Subdiagnostic)]

+

It is common in the compiler to write a function that conditionally adds a +specific subdiagnostic to an error if it is applicable. Oftentimes these +subdiagnostics could be represented using a diagnostic struct even if the +overall diagnostic could not. In this circumstance, the Subdiagnostic +derive can be used to represent a partial diagnostic (e.g a note, label, help or +suggestion) as a struct.

+

Consider the definition of the "expected return type" label +shown below:

+
#![allow(unused)]
+fn main() {
+#[derive(Subdiagnostic)]
+pub enum ExpectedReturnTypeLabel<'tcx> {
+    #[label(hir_analysis_expected_default_return_type)]
+    Unit {
+        #[primary_span]
+        span: Span,
+    },
+    #[label(hir_analysis_expected_return_type)]
+    Other {
+        #[primary_span]
+        span: Span,
+        expected: Ty<'tcx>,
+    },
+}
+}
+
+

Like Diagnostic, Subdiagnostic can be derived for structs or +enums. Attributes that are placed on the type for structs are placed on each +variants for enums (or vice versa). Each Subdiagnostic should have one +attribute applied to the struct or each variant, one of:

+
    +
  • #[label(..)] for defining a label
  • +
  • #[note(..)] for defining a note
  • +
  • #[help(..)] for defining a help
  • +
  • #[warning(..)] for defining a warning
  • +
  • #[suggestion{,_hidden,_short,_verbose}(..)] for defining a suggestion
  • +
+

All of the above must provide a slug as the first positional argument (a path +to an item in rustc_errors::fluent::*). A slug uniquely identifies the +diagnostic and is also how the compiler knows what error message to emit (in +the default locale of the compiler, or in the locale requested by the user). +See translation documentation to learn more about how +translatable error messages are written and how slug items are generated.

+

In our example, the Fluent message for the "expected return type" label +looks like this:

+
hir_analysis_expected_default_return_type = expected `()` because of default return type
+
+hir_analysis_expected_return_type = expected `{$expected}` because of return type
+
+

Using the #[primary_span] attribute on a field (with type Span) will denote +the primary span of the subdiagnostic. A primary span is only necessary for a +label or suggestion, which can not be spanless.

+

Every field of the type/variant which does not have an annotation is available +in Fluent messages as a variable. Fields can be annotated #[skip_arg] if this +is undesired.

+

Like Diagnostic, Subdiagnostic supports Option<T> and +Vec<T> fields.

+

Suggestions can be emitted using one of four attributes on the type/variant:

+
    +
  • #[suggestion(..., code = "...", applicability = "...")]
  • +
  • #[suggestion_hidden(..., code = "...", applicability = "...")]
  • +
  • #[suggestion_short(..., code = "...", applicability = "...")]
  • +
  • #[suggestion_verbose(..., code = "...", applicability = "...")]
  • +
+

Suggestions require #[primary_span] be set on a field and can have the +following sub-attributes:

+
    +
  • The first positional argument specifies the path to a item in +rustc_errors::fluent corresponding to the Fluent attribute with the message +and defaults to the equivalent of .suggestion.
  • +
  • code specifies the code that should be suggested as a replacement and is a +format string (e.g. {field_name} would be replaced by the value of the +field_name field of the struct), not a Fluent identifier.
  • +
  • applicability can be used to specify the applicability in the attribute, it +cannot be used when the field's type contains an Applicability.
  • +
+

Applicabilities can also be specified as a field (of type Applicability) +using the #[applicability] attribute.

+

In the end, the Subdiagnostic derive will generate an implementation +of Subdiagnostic that looks like the following:

+
#![allow(unused)]
+fn main() {
+impl<'tcx> Subdiagnostic for ExpectedReturnTypeLabel<'tcx> {
+    fn add_to_diag(self, diag: &mut rustc_errors::Diagnostic) {
+        use rustc_errors::{Applicability, IntoDiagArg};
+        match self {
+            ExpectedReturnTypeLabel::Unit { span } => {
+                diag.span_label(span, rustc_errors::fluent::hir_analysis_expected_default_return_type)
+            }
+            ExpectedReturnTypeLabel::Other { span, expected } => {
+                diag.set_arg("expected", expected);
+                diag.span_label(span, rustc_errors::fluent::hir_analysis_expected_return_type)
+            }
+        }
+    }
+}
+}
+
+

Once defined, a subdiagnostic can be used by passing it to the subdiagnostic +function (example and example) on a +diagnostic or by assigning it to a #[subdiagnostic]-annotated field of a +diagnostic struct.

+

Reference

+

#[derive(Subdiagnostic)] supports the following attributes:

+
    +
  • #[label(slug)], #[help(slug)], #[warning(slug)] or #[note(slug)] +
      +
    • Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes.
    • +
    • Mandatory
    • +
    • Defines the type to be representing a label, help or note.
    • +
    • Slug (Mandatory) +
        +
      • Uniquely identifies the diagnostic and corresponds to its Fluent message, +mandatory.
      • +
      • A path to an item in rustc_errors::fluent, e.g. +rustc_errors::fluent::hir_analysis_field_already_declared +(rustc_errors::fluent is implicit in the attribute, so just +hir_analysis_field_already_declared).
      • +
      • See translation documentation.
      • +
      +
    • +
    +
  • +
  • #[suggestion{,_hidden,_short,_verbose}(slug, code = "...", applicability = "...")] +
      +
    • Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes.
    • +
    • Mandatory
    • +
    • Defines the type to be representing a suggestion.
    • +
    • Slug (Mandatory) +
        +
      • A path to an item in rustc_errors::fluent, e.g. +rustc_errors::fluent::hir_analysis_field_already_declared +(rustc_errors::fluent is implicit in the attribute, so just +hir_analysis::field_already_declared). Fluent attributes for all messages +exist as top-level items in that module (so hir_analysis_message.attr is just +hir_analysis::attr).
      • +
      • See translation documentation.
      • +
      • Defaults to rustc_errors::fluent::_subdiag::suggestion (or
      • +
      • .suggestion in Fluent).
      • +
      +
    • +
    • code = "..."/code("...", ...) (Mandatory) +
        +
      • One or multiple format strings indicating the code to be suggested as a +replacement. Multiple values signify multiple possible replacements.
      • +
      +
    • +
    • applicability = "..." (Optional) +
        +
      • Mutually exclusive with #[applicability] on a field.
      • +
      • Value is the applicability of the suggestion.
      • +
      • String which must be one of: +
          +
        • machine-applicable
        • +
        • maybe-incorrect
        • +
        • has-placeholders
        • +
        • unspecified
        • +
        +
      • +
      +
    • +
    +
  • +
  • #[multipart_suggestion{,_hidden,_short,_verbose}(slug, applicability = "...")] +
      +
    • Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes.
    • +
    • Mandatory
    • +
    • Defines the type to be representing a multipart suggestion.
    • +
    • Slug (Mandatory): see #[suggestion]
    • +
    • applicability = "..." (Optional): see #[suggestion]
    • +
    +
  • +
  • #[primary_span] (Mandatory for labels and suggestions; optional otherwise; not applicable +to multipart suggestions) +
      +
    • Applied to Span fields.
    • +
    • Indicates the primary span of the subdiagnostic.
    • +
    +
  • +
  • #[suggestion_part(code = "...")] (Mandatory; only applicable to multipart suggestions) +
      +
    • Applied to Span fields.
    • +
    • Indicates the span to be one part of the multipart suggestion.
    • +
    • code = "..." (Mandatory) +
        +
      • Value is a format string indicating the code to be suggested as a +replacement.
      • +
      +
    • +
    +
  • +
  • #[applicability] (Optional; only applicable to (simple and multipart) suggestions) +
      +
    • Applied to Applicability fields.
    • +
    • Indicates the applicability of the suggestion.
    • +
    +
  • +
  • #[skip_arg] (Optional) +
      +
    • Applied to any field.
    • +
    • Prevents the field from being provided as a diagnostic argument.
    • +
    +
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/diagnostics/error-codes.html b/diagnostics/error-codes.html new file mode 100644 index 000000000..7a64c28b3 --- /dev/null +++ b/diagnostics/error-codes.html @@ -0,0 +1,279 @@ + + + + + + Error codes - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Error codes

+

We generally try to assign each error message a unique code like E0123. These +codes are defined in the compiler in the diagnostics.rs files found in each +crate, which basically consist of macros. All error codes have an associated +explanation: new error codes must include them. Note that not all historical +(no longer emitted) error codes have explanations.

+

Error explanations

+

The explanations are written in Markdown (see the CommonMark Spec for +specifics around syntax), and all of them are linked in the rustc_error_codes +crate. Please read RFC 1567 for details on how to format and write long error +codes. As of February 2023, there is an +effort1 to replace this largely outdated RFC with a new more +flexible standard.

+

Error explanations should expand on the error message and provide details about +why the error occurs. It is not helpful for users to copy-paste a quick fix; +explanations should help users understand why their code cannot be accepted by +the compiler. Rust prides itself on helpful error messages and long-form +explanations are no exception. However, before error explanations are +overhauled1 it is a bit open as to how exactly they should be +written, as always: ask your reviewer or ask around on the Rust Discord or Zulip.

+
1 +

See the draft RFC here.

+
+

Allocating a fresh code

+

Error codes are stored in compiler/rustc_error_codes.

+

To create a new error, you first need to find the next available +code. You can find it with tidy:

+
./x test tidy
+
+

This will invoke the tidy script, which generally checks that your code obeys +our coding conventions. Some of these jobs check error codes and ensure that +there aren't duplicates, etc (the tidy check is defined in +src/tools/tidy/src/error_codes.rs). Once it is finished with that, tidy will +print out the highest used error code:

+
...
+tidy check
+Found 505 error codes
+Highest error code: `E0591`
+...
+
+

Here we see the highest error code in use is E0591, so we probably want +E0592. To be sure, run rg E0592 and check, you should see no references.

+

You will have to write an extended description for your error, +which will go in rustc_error_codes/src/error_codes/E0592.md. +To register the error, open rustc_error_codes/src/error_codes.rs and add the +code (in its proper numerical order) into register_diagnostics! macro, like +this:

+
#![allow(unused)]
+fn main() {
+register_diagnostics! {
+    ...
+    E0592: include_str!("./error_codes/E0592.md"),
+}
+}
+
+

To actually issue the error, you can use the struct_span_code_err! macro:

+
#![allow(unused)]
+fn main() {
+struct_span_code_err!(self.dcx(), // some path to the `DiagCtxt` here
+                 span, // whatever span in the source you want
+                 E0592, // your new error code
+                 fluent::example::an_error_message)
+    .emit() // actually issue the error
+}
+
+

If you want to add notes or other snippets, you can invoke methods before you +call .emit():

+
#![allow(unused)]
+fn main() {
+struct_span_code_err!(...)
+    .span_label(another_span, fluent::example::example_label)
+    .span_note(another_span, fluent::example::separate_note)
+    .emit()
+}
+
+

For an example of a PR adding an error code, see #76143.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/diagnostics/error-guaranteed.html b/diagnostics/error-guaranteed.html new file mode 100644 index 000000000..9875f910f --- /dev/null +++ b/diagnostics/error-guaranteed.html @@ -0,0 +1,230 @@ + + + + + + ErrorGuaranteed - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

ErrorGuaranteed

+

The previous sections have been about the error message that a user of the +compiler sees. But emitting an error can also have a second important side +effect within the compiler source code: it generates an +ErrorGuaranteed.

+

ErrorGuaranteed is a zero-sized type that is unconstructable outside of the +rustc_errors crate. It is generated whenever an error is reported +to the user, so that if your compiler code ever encounters a value of type +ErrorGuaranteed, the compilation is statically guaranteed to fail. This is +useful for avoiding unsoundness bugs because you can statically check that an +error code path leads to a failure.

+

There are some important considerations about the usage of ErrorGuaranteed:

+
    +
  • It does not convey information about the kind of error. For example, the +error may be due (indirectly) to a delayed bug or other compiler error. +Thus, you should not rely on +ErrorGuaranteed when deciding whether to emit an error, or what kind of error +to emit.
  • +
  • ErrorGuaranteed should not be used to indicate that a compilation will +emit an error in the future. It should be used to indicate that an error +has already been emitted -- that is, the emit() function has +already been called. For example, if we detect that a future part of the +compiler will error, we cannot use ErrorGuaranteed unless we first emit +an error or delayed bug ourselves.
  • +
+

Thankfully, in most cases, it should be statically impossible to abuse +ErrorGuaranteed.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/diagnostics/lintstore.html b/diagnostics/lintstore.html new file mode 100644 index 000000000..76dceccfc --- /dev/null +++ b/diagnostics/lintstore.html @@ -0,0 +1,288 @@ + + + + + + LintStore - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Lints

+

This page documents some of the machinery around lint registration and how we +run lints in the compiler.

+

The LintStore is the central piece of infrastructure, around which +everything rotates. The LintStore is held as part of the Session, and it +gets populated with the list of lints shortly after the Session is created.

+

Lints vs. lint passes

+

There are two parts to the linting mechanism within the compiler: lints and +lint passes. Unfortunately, a lot of the documentation we have refers to both +of these as just "lints."

+

First, we have the lint declarations themselves, +and this is where the name and default lint level and other metadata come from. +These are normally defined by way of the declare_lint! macro, +which boils down to a static with type &rustc_lint_defs::Lint +(although this may change in the future, +as the macro is somewhat unwieldy to add new fields to, +like all macros).

+

As of Aug 2022, +we lint against direct declarations without the use of the macro.

+

Lint declarations don't carry any "state" - they are merely global identifiers +and descriptions of lints. We assert at runtime that they are not registered +twice (by lint name).

+

Lint passes are the meat of any lint. Notably, there is not a one-to-one +relationship between lints and lint passes; a lint might not have any lint pass +that emits it, it could have many, or just one -- the compiler doesn't track +whether a pass is in any way associated with a particular lint, and frequently +lints are emitted as part of other work (e.g., type checking, etc.).

+

Registration

+

High-level overview

+

In rustc_interface::run_compiler, +the LintStore is created, +and all lints are registered.

+

There are three 'sources' of lints:

+
    +
  • internal lints: lints only used by the rustc codebase
  • +
  • builtin lints: lints built into the compiler and not provided by some outside +source
  • +
  • rustc_interface::Configregister_lints: lints passed into the compiler +during construction
  • +
+

Lints are registered via the LintStore::register_lint function. This should +happen just once for any lint, or an ICE will occur.

+

Once the registration is complete, we "freeze" the lint store by placing it in +an Lrc.

+

Lint passes are registered separately into one of the categories +(pre-expansion, early, late, late module). Passes are registered as a closure +-- i.e., impl Fn() -> Box<dyn X>, where dyn X is either an early or late +lint pass trait object. When we run the lint passes, we run the closure and +then invoke the lint pass methods. The lint pass methods take &mut self so +they can keep track of state internally.

+

Internal lints

+

These are lints used just by the compiler or drivers like clippy. They can be +found in rustc_lint::internal.

+

An example of such a lint is the check that lint passes are implemented using +the declare_lint_pass! macro and not by hand. This is accomplished with the +LINT_PASS_IMPL_WITHOUT_MACRO lint.

+

Registration of these lints happens in the rustc_lint::register_internals +function which is called when constructing a new lint store inside +rustc_lint::new_lint_store.

+

Builtin Lints

+

These are primarily described in two places, +rustc_lint_defs::builtin and rustc_lint::builtin. +Often the first provides the definitions for the lints themselves, +and the latter provides the lint pass definitions (and implementations), +but this is not always true.

+

The builtin lint registration happens in +the rustc_lint::register_builtins function. +Just like with internal lints, +this happens inside of rustc_lint::new_lint_store.

+

Driver lints

+

These are the lints provided by drivers via the rustc_interface::Config +register_lints field, which is a callback. Drivers should, if finding it +already set, call the function currently set within the callback they add. The +best way for drivers to get access to this is by overriding the +Callbacks::config function which gives them direct access to the Config +structure.

+

Compiler lint passes are combined into one pass

+

Within the compiler, for performance reasons, we usually do not register dozens +of lint passes. Instead, we have a single lint pass of each variety (e.g., +BuiltinCombinedModuleLateLintPass) which will internally call all of the +individual lint passes; this is because then we get the benefits of static over +dynamic dispatch for each of the (often empty) trait methods.

+

Ideally, we'd not have to do this, since it adds to the complexity of +understanding the code. However, with the current type-erased lint store +approach, it is beneficial to do so for performance reasons.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/diagnostics/sessiondiagnostic.html b/diagnostics/sessiondiagnostic.html new file mode 100644 index 000000000..eba8876f1 --- /dev/null +++ b/diagnostics/sessiondiagnostic.html @@ -0,0 +1,12 @@ + + + + + Redirecting... + + + + +

Redirecting to... diagnostic-structs.html.

+ + diff --git a/diagnostics/translation.html b/diagnostics/translation.html new file mode 100644 index 000000000..f29414b83 --- /dev/null +++ b/diagnostics/translation.html @@ -0,0 +1,376 @@ + + + + + + Translation - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Translation

+
+rustc's current diagnostics translation infrastructure (as of + October 2024 +) unfortunately causes some friction for compiler contributors, and the current +infrastructure is mostly pending a redesign that better addresses needs of both +compiler contributors and translation teams. Note that there is no current +active redesign proposals (as of + October 2024 +)! +

Please see the tracking issue https://github.com/rust-lang/rust/issues/132181 +for status updates.

+

We have downgraded the internal lints untranslatable_diagnostic and +diagnostic_outside_of_impl. Those internal lints previously required new code +to use the current translation infrastructure. However, because the translation +infra is waiting for a yet-to-be-proposed redesign and thus rework, we are not +mandating usage of current translation infra. Use the infra if you want to or +otherwise makes the code cleaner, but otherwise sidestep the translation infra +if you need more flexibility.

+
+

rustc's diagnostic infrastructure supports translatable diagnostics using +Fluent.

+

Writing translatable diagnostics

+

There are two ways of writing translatable diagnostics:

+
    +
  1. For simple diagnostics, using a diagnostic (or subdiagnostic) derive. +("Simple" diagnostics being those that don't require a lot of logic in +deciding to emit subdiagnostics and can therefore be represented as +diagnostic structs). See the diagnostic and subdiagnostic structs +documentation.
  2. +
  3. Using typed identifiers with Diag APIs (in +Diagnostic or Subdiagnostic or LintDiagnostic implementations).
  4. +
+

When adding or changing a translatable diagnostic, +you don't need to worry about the translations. +Only updating the original English message is required. +Currently, +each crate which defines translatable diagnostics has its own Fluent resource, +which is a file named messages.ftl, +located in the root of the crate +(such ascompiler/rustc_expand/messages.ftl).

+

Fluent

+

Fluent is built around the idea of "asymmetric localization", which aims to +decouple the expressiveness of translations from the grammar of the source +language (English in rustc's case). Prior to translation, rustc's diagnostics +relied heavily on interpolation to build the messages shown to the users. +Interpolated strings are hard to translate because writing a natural-sounding +translation might require more, less, or just different interpolation than the +English string, all of which would require changes to the compiler's source +code to support.

+

Diagnostic messages are defined in Fluent resources. A combined set of Fluent +resources for a given locale (e.g. en-US) is known as Fluent bundle.

+
typeck_address_of_temporary_taken = cannot take address of a temporary
+
+

In the above example, typeck_address_of_temporary_taken is the identifier for +a Fluent message and corresponds to the diagnostic message in English. Other +Fluent resources can be written which would correspond to a message in another +language. Each diagnostic therefore has at least one Fluent message.

+
typeck_address_of_temporary_taken = cannot take address of a temporary
+    .label = temporary value
+
+

By convention, diagnostic messages for subdiagnostics are specified as +"attributes" on Fluent messages (additional related messages, denoted by the +.<attribute-name> syntax). In the above example, label is an attribute of +typeck_address_of_temporary_taken which corresponds to the message for the +label added to this diagnostic.

+

Diagnostic messages often interpolate additional context into the message shown +to the user, such as the name of a type or of a variable. Additional context to +Fluent messages is provided as an "argument" to the diagnostic.

+
typeck_struct_expr_non_exhaustive =
+    cannot create non-exhaustive {$what} using struct expression
+
+

In the above example, the Fluent message refers to an argument named what +which is expected to exist (how arguments are provided to diagnostics is +discussed in detail later).

+

You can consult the Fluent documentation for other usage examples of Fluent +and its syntax.

+

Guideline for message naming

+

Usually, fluent uses - for separating words inside a message name. However, +_ is accepted by fluent as well. As _ fits Rust's use cases better, due to +the identifiers on the Rust side using _ as well, inside rustc, - is not +allowed for separating words, and instead _ is recommended. The only exception +is for leading -s, for message names like -passes_see_issue.

+

Guidelines for writing translatable messages

+

For a message to be translatable into different languages, all of the +information required by any language must be provided to the diagnostic as an +argument (not just the information required in the English message).

+

As the compiler team gain more experience writing diagnostics that have all of +the information necessary to be translated into different languages, this page +will be updated with more guidance. For now, the Fluent documentation has +excellent examples of translating messages into different locales and the +information that needs to be provided by the code to do so.

+

Compile-time validation and typed identifiers

+

rustc's fluent_messages macro performs compile-time validation of Fluent +resources and generates code to make it easier to refer to Fluent messages in +diagnostics.

+

Compile-time validation of Fluent resources will emit any parsing errors +from Fluent resources while building the compiler, preventing invalid Fluent +resources from causing panics in the compiler. Compile-time validation also +emits an error if multiple Fluent messages have the same identifier.

+

Internals

+

Various parts of rustc's diagnostic internals are modified in order to support +translation.

+

Messages

+

All of rustc's traditional diagnostic APIs (e.g. struct_span_err or note) +take any message that can be converted into a DiagMessage (or +SubdiagMessage).

+

rustc_error_messages::DiagMessage can represent legacy non-translatable +diagnostic messages and translatable messages. Non-translatable messages are +just Strings. Translatable messages are just a &'static str with the +identifier of the Fluent message (sometimes with an additional &'static str +with an attribute).

+

DiagMessage never needs to be interacted with directly: +DiagMessage constants are created for each diagnostic message in a +Fluent resource (described in more detail below), or DiagMessages will +either be created in the macro-generated code of a diagnostic derive.

+

rustc_error_messages::SubdiagMessage is similar, it can correspond to a +legacy non-translatable diagnostic message or the name of an attribute to a +Fluent message. Translatable SubdiagMessages must be combined with a +DiagMessage (using DiagMessage::with_subdiagnostic_message) to +be emitted (an attribute name on its own is meaningless without a corresponding +message identifier, which is what DiagMessage provides).

+

Both DiagMessage and SubdiagMessage implement Into for any +type that can be converted into a string, and converts these into +non-translatable diagnostics - this keeps all existing diagnostic calls +working.

+

Arguments

+

Additional context for Fluent messages which are interpolated into message +contents needs to be provided to translatable diagnostics.

+

Diagnostics have a set_arg function that can be used to provide this +additional context to a diagnostic.

+

Arguments have both a name (e.g. "what" in the earlier example) and a value. +Argument values are represented using the DiagArgValue type, which is +just a string or a number. rustc types can implement IntoDiagArg with +conversion into a string or a number, and common types like Ty<'tcx> already +have such implementations.

+

set_arg calls are handled transparently by diagnostic derives but need to be +added manually when using diagnostic builder APIs.

+

Loading

+

rustc makes a distinction between the "fallback bundle" for en-US that is used +by default and when another locale is missing a message; and the primary fluent +bundle which is requested by the user.

+

Diagnostic emitters implement the Emitter trait which has two functions for +accessing the fallback and primary fluent bundles (fallback_fluent_bundle and +fluent_bundle respectively).

+

Emitter also has member functions with default implementations for performing +translation of a DiagMessage using the results of +fallback_fluent_bundle and fluent_bundle.

+

All of the emitters in rustc load the fallback Fluent bundle lazily, only +reading Fluent resources and parsing them when an error message is first being +translated (for performance reasons - it doesn't make sense to do this if no +error is being emitted). rustc_error_messages::fallback_fluent_bundle returns +a std::lazy::Lazy<FluentBundle> which is provided to emitters and evaluated +in the first call to Emitter::fallback_fluent_bundle.

+

The primary Fluent bundle (for the user's desired locale) is expected to be +returned by Emitter::fluent_bundle. This bundle is used preferentially when +translating messages, the fallback bundle is only used if the primary bundle is +missing a message or not provided.

+

There are no locale bundles distributed with the compiler, +but mechanisms are implemented for loading them.

+
    +
  • -Ztranslate-additional-ftl can be used to load a specific resource as the +primary bundle for testing purposes.
  • +
  • -Ztranslate-lang can be provided a language identifier (something like +en-US) and will load any Fluent resources found in +$sysroot/share/locale/$locale/ directory (both the user provided +sysroot and any sysroot candidates).
  • +
+

Primary bundles are not currently loaded lazily and if requested will be loaded +at the start of compilation regardless of whether an error occurs. Lazily +loading primary bundles is possible if it can be assumed that loading a bundle +won't fail. Bundle loading can fail if a requested locale is missing, Fluent +files are malformed, or a message is duplicated in multiple resources.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/early-late-bound-params/early-late-bound-implementation-nuances.html b/early-late-bound-params/early-late-bound-implementation-nuances.html new file mode 100644 index 000000000..798cb637f --- /dev/null +++ b/early-late-bound-params/early-late-bound-implementation-nuances.html @@ -0,0 +1,373 @@ + + + + + + Implementation nuances of early/late bound parameters - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Early and Late Bound Parameter Implementation Nuances

+

Understanding this page likely requires a rudimentary understanding of higher ranked +trait bounds/for<'a>and also what types such as dyn for<'a> Trait<'a> and +for<'a> fn(&'a u32) mean. Reading the nomincon chapter +on HRTB may be useful for understanding this syntax. The meaning of for<'a> fn(&'a u32) +is incredibly similar to the meaning of T: for<'a> Trait<'a>.

+

What does it mean for parameters to be early or late bound

+

All function definitions conceptually have a ZST (this is represented by TyKind::FnDef in rustc). +The only generics on this ZST are the early bound parameters of the function definition. e.g.

+
fn foo<'a>(_: &'a u32) {}
+
+fn main() {
+    let b = foo;
+    //  ^ `b` has type `FnDef(foo, [])` (no args because `'a` is late bound)
+    assert!(std::mem::size_of_val(&b) == 0);
+}
+
+

In order to call b the late bound parameters do need to be provided, these are inferred at the +call site instead of when we refer to foo.

+
fn main() {
+    let b = foo;
+    let a: &'static u32 = &10;
+    foo(a);
+    // the lifetime argument for `'a` on `foo` is inferred at the callsite
+    // the generic parameter `'a` on `foo` is inferred to `'static` here
+}
+
+

Because late bound parameters are not part of the FnDef's args this allows us to prove trait +bounds such as F: for<'a> Fn(&'a u32) where F is foo's FnDef. e.g.

+
fn foo_early<'a, T: Trait<'a>>(_: &'a u32, _: T) {}
+fn foo_late<'a, T>(_: &'a u32, _: T) {}
+
+fn accepts_hr_func<F: for<'a> Fn(&'a u32, u32)>(_: F) {}
+
+fn main() {
+    // doesn't work, the substituted bound is `for<'a> FnDef<'?0>: Fn(&'a u32, u32)`
+    // `foo_early` only implements `for<'a> FnDef<'a>: Fn(&'a u32, u32)`- the lifetime
+    // of the borrow in the function argument must be the same as the lifetime
+    // on the `FnDef`.
+    accepts_hr_func(foo_early);
+
+    // works, the substituted bound is `for<'a> FnDef: Fn(&'a u32, u32)`
+    accepts_hr_func(foo_late);
+}
+
+// the builtin `Fn` impls for `foo_early` and `foo_late` look something like:
+// `foo_early`
+impl<'a, T: Trait<'a>> Fn(&'a u32, T) for FooEarlyFnDef<'a, T> { ... }
+// `foo_late`
+impl<'a, T> Fn(&'a u32, T) for FooLateFnDef<T> { ... }
+
+
+

Early bound parameters are present on the FnDef. Late bound generic parameters are not present +on the FnDef but are instead constrained by the builtin Fn* impl.

+

The same distinction applies to closures. Instead of FnDef we are talking about the anonymous +closure type. Closures are currently unsound in +ways that are closely related to the distinction between early/late bound +parameters (more on this later)

+

The early/late boundness of generic parameters is only relevant for the desugaring of +functions/closures into types with builtin Fn* impls. It does not make sense to talk about +in other contexts.

+

The generics_of query in rustc only contains early bound parameters. In this way it acts more +like generics_of(my_func) is the generics for the FnDef than the generics provided to the function +body although it's not clear to the author of this section if this was the actual justification for +making generics_of behave this way.

+

What parameters are currently late bound

+

Below are the current requirements for determining if a generic parameter is late bound. It is worth +keeping in mind that these are not necessarily set in stone and it is almost certainly possible to +be more flexible.

+

Must be a lifetime parameter

+

Rust can't support types such as for<T> dyn Trait<T> or for<T> fn(T), this is a +fundamental limitation of the language as we are required to monomorphize type/const +parameters and cannot do so behind dynamic dispatch. (technically we could probably +support for<T> dyn MarkerTrait<T> as there is nothing to monomorphize)

+

Not being able to support for<T> dyn Trait<T> resulted in making all type and const +parameters early bound. Only lifetime parameters can be late bound.

+

Must not appear in the where clauses

+

In order for a generic parameter to be late bound it must not appear in any where clauses. +This is currently an incredibly simplistic check that causes lifetimes to be early bound even +if the where clause they appear in are always true, or implied by well formedness of function +arguments. e.g.

+
#![allow(unused)]
+fn main() {
+fn foo1<'a: 'a>(_: &'a u32) {}
+//     ^^ early bound parameter because it's in a `'a: 'a` clause
+//        even though the bound obviously holds all the time
+fn foo2<'a, T: Trait<'a>(a: T, b: &'a u32) {}
+//     ^^ early bound parameter because it's used in the `T: Trait<'a>` clause
+fn foo3<'a, T: 'a>(_: &'a T) {}
+//     ^^ early bound parameter because it's used in the `T: 'a` clause
+//        even though that bound is implied by wellformedness of `&'a T`
+fn foo4<'a, 'b: 'a>(_: Inv<&'a ()>, _: Inv<&'b ()>) {}
+//      ^^  ^^         ^^^ note:
+//      ^^  ^^         `Inv` stands for `Invariant` and is used to
+//      ^^  ^^          make the type parameter invariant. This
+//      ^^  ^^          is necessary for demonstration purposes as
+//      ^^  ^^          `for<'a, 'b> fn(&'a (), &'b ())` and
+//      ^^  ^^          `for<'a> fn(&'a u32, &'a u32)` are subtypes-
+//      ^^  ^^          of each other which makes the bound trivially
+//      ^^  ^^          satisfiable when making the fnptr. `Inv`
+//      ^^  ^^          disables this subtyping.
+//      ^^  ^^
+//      ^^^^^^ both early bound parameters because they are present in the
+//            `'b: 'a` clause
+}
+
+

The reason for this requirement is that we cannot represent the T: Trait<'a> or 'a: 'b clauses +on a function pointer. for<'a, 'b> fn(Inv<&'a ()>, Inv<&'b ()>) is not a valid function pointer to +representfoo4 as it would allow calling the function without 'b: 'a holding.

+

Must be constrained by where clauses or function argument types

+

The builtin impls of the Fn* traits for closures and FnDefs cannot not have any unconstrained +parameters. For example the following impl is illegal:

+
#![allow(unused)]
+fn main() {
+impl<'a> Trait for u32 { type Assoc = &'a u32; }
+}
+
+

We must not end up with a similar impl for the Fn* traits e.g.

+
#![allow(unused)]
+fn main() {
+impl<'a> Fn<()> for FnDef { type Assoc = &'a u32 }
+}
+
+

Violating this rule can trivially lead to unsoundness as seen in #84366. +Additionally if we ever support late bound type params then an impl like:

+
#![allow(unused)]
+fn main() {
+impl<T> Fn<()> for FnDef { type Assoc = T; }
+}
+
+

would break the compiler in various ways.

+

In order to ensure that everything functions correctly, we do not allow generic parameters to +be late bound if it would result in a builtin impl that does not constrain all of the generic +parameters on the builtin impl. Making a generic parameter be early bound trivially makes it be +constrained by the builtin impl as it ends up on the self type.

+

Because of the requirement that late bound parameters must not appear in where clauses, checking +this is simpler than the rules for checking impl headers constrain all the parameters on the impl. +We only have to ensure that all late bound parameters appear at least once in the function argument +types outside of an alias (e.g. an associated type).

+

The requirement that they not indirectly be in the args of an alias for it to count is the +same as why the follow code is forbidden:

+
#![allow(unused)]
+fn main() {
+impl<T: Trait> OtherTrait for <T as Trait>::Assoc { type Assoc = T }
+}
+
+

There is no guarantee that <T as Trait>::Assoc will normalize to different types for every +instantiation of T. If we were to allow this impl we could get overlapping impls and the +same is true of the builtin Fn* impls.

+

Making more generic parameters late bound

+

It is generally considered desirable for more parameters to be late bound as it makes +the builtin Fn* impls more flexible. Right now many of the requirements for making +a parameter late bound are overly restrictive as they are tied to what we can currently +(or can ever) do with fn ptrs.

+

It would be theoretically possible to support late bound params in where-clauses in the +language by introducing implication types which would allow us to express types such as: +for<'a, 'b: 'a> fn(Inv<&'a u32>, Inv<&'b u32>) which would ensure 'b: 'a is upheld when +calling the function pointer.

+

It would also be theoretically possible to support it by making the coercion to a fn ptr +instantiate the parameter with an infer var while still allowing the FnDef to not have the +generic parameter present as trait impls are perfectly capable of representing the where clauses +on the function on the impl itself. This would also allow us to support late bound type/const +vars allowing bounds like F: for<T> Fn(T) to hold.

+

It is almost somewhat unclear if we can change the Fn traits to be structured differently +so that we never have to make a parameter early bound just to make the builtin impl have all +generics be constrained. Of all the possible causes of a generic parameter being early bound +this seems the most difficult to remove.

+

Whether these would be good ideas to implement is a separate question- they are only brought +up to illustrate that the current rules are not necessarily set in stone and a result of +"its the only way of doing this".

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/early-late-bound-params/early-late-bound-summary.html b/early-late-bound-params/early-late-bound-summary.html new file mode 100644 index 000000000..340988ed3 --- /dev/null +++ b/early-late-bound-params/early-late-bound-summary.html @@ -0,0 +1,232 @@ + + + + + + Early vs Late bound parameters - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Early/Late bound parameters

+

This section discusses what it means for generic parameters to be early or late bound.

+
#![allow(unused)]
+fn main() {
+fn foo<'a, T>(b: &'a T) -> &'a T { b }
+//     ^^  ^early bound
+//     ^^
+//     ^^late bound
+}
+
+

Generally when referring to an item with generic parameters you must specify a list of generic arguments corresponding to the item's generic parameters. In +some cases it is permitted to elide these arguments but still, implicitly, a set of arguments are provided (i.e. Vec::default() desugars to Vec::<_>::default()).

+

For functions this is not necessarily the case, for example if we take the function foo from the example above and write the following code:

+
fn main() {
+    let f = foo::<_>;
+
+    let b = String::new();
+    let c = String::new();
+    
+    f(&b);
+    drop(b);
+    f(&c);
+}
+
+

This code compiles perfectly fine even though there is no single lifetime that could possibly be specified in foo::<_> that would allow for both +the &b and &c borrows to be used as arguments (note: the drop(b) line forces the &b borrow to be shorter than the &c borrow). This works because +the 'a lifetime is late bound.

+

A generic parameter being late bound means that when we write foo::<_> we do not actually provide an argument for that parameter, instead we wait until calling the function to provide the generic argument. In the above example this means that we are doing something like f::<'_>(&b); and f::<'_>(&c); (although in practice we do not actually support turbofishing late bound parameters in this manner)

+

It may be helpful to think of "early bound parameter" or "late bound parameter" as meaning "early provided parameter" and "late provided parameter", i.e. we provide the argument to the parameter either early (when naming the function) or late (when calling it).

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/early-late-bound-params/turbofishing-and-early-late-bound.html b/early-late-bound-params/turbofishing-and-early-late-bound.html new file mode 100644 index 000000000..87ea7c081 --- /dev/null +++ b/early-late-bound-params/turbofishing-and-early-late-bound.html @@ -0,0 +1,308 @@ + + + + + + Interactions with turbofishing - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Turbofishing's interactions with early/late bound parameters

+

The early/late bound parameter distinction on functions introduces some complications +when providing generic arguments to functions. This document discusses what those are +and how they might interact with future changes to make more things late bound.

+

Can't turbofish generic arguments on functions sometimes

+

When a function has any late bound lifetime parameters (be they explicitly defined or +implicitly introduced via lifetime elision) we disallow specifying any lifetime arguments +on the function. Sometimes this is a hard error other times it is a future compat lint +(late_bound_lifetime_arguments).

+
fn early<'a: 'a>(a: &'a ()) -> &'a () { a }
+fn late<'a>(a: &'a ()) -> &'a () { a }
+
+fn mixed<'a, 'b: 'b>(a: &'a (), b: &'b ()) -> &'a () { a }
+
+struct Foo;
+impl Foo {
+    fn late<'a>(self, a: &'a ()) -> &'a () { a }
+}
+
+fn main() {
+    // fine
+    let f = early::<'static>;
+    
+    // some variation of hard errors and future compat lints
+    Foo.late::<'static>(&());
+    let f = late::<'static>;
+    let f = mixed::<'static, 'static>;
+    let f = mixed::<'static>;
+    late::<'static>(&());
+}
+
+

The justification for this is that late bound parameters are not present on the +FnDef so the arguments to late bound parameters can't be present in the substs +for the type. i.e. the late function in the above code snippet would not have +any generic parameters on the FnDef zst:

+
#![allow(unused)]
+fn main() {
+// example desugaring of the `late` function and its zst + builtin Fn impl
+struct LateFnDef;
+impl<'a> Fn<(&'a ())> for LateFnDef {
+    type Output = &'a ();
+    ...
+}
+}
+
+

The cause for some situations giving future compat lints and others giving hard errors +is a little arbitrary but explainable:

+
    +
  • It's always a hard error for method calls
  • +
  • It's only a hard error on paths to free functions if there is no unambiguous way to +create the substs for the fndef from the lifetime arguments. (i.e. the amount of +lifetimes provided must be exactly equal to the amount of early bound lifetimes or +else it's a hard error)
  • +
+

Back compat issues from turning early bound to late bound

+

Because of the previously mentioned restriction on turbofishing generic arguments, it +is a breaking change to upgrade a lifetime from early bound to late bound as it can cause +existing turbofishies to become hard errors/future compat lints.

+

Many t-types members have expressed interest in wanting more parameters to be late bound. +We cannot do so if making something late bound is going to break code that many would +expect to work (judging by the future compat lint issue many people do expect to be able +to turbofish late bound parameters).

+

Interactions with late bound type/const parameters

+

If we were to make some type/const parameters late bound we would definitely not want +to disallow turbofishing them as it presumably(?) would break a Tonne of code.

+

While lifetimes do differ from type/consts in some ways I(BoxyUwU) do not believe there +is any justification for why it would make sense to allow turbofishing late bound +type/const parameters but not late bound lifetimes.

+

Removing the hard error/fcw

+

From reasons above it seems reasonable that we may want to remove the hard error and fcw +(removing the errors/fcw is definitely a blocker for making more things late bound).

+

example behaviour:

+
fn late<'a>(a: &'a ()) -> &'a () { a }
+
+fn accepts_fn(_: impl for<'a> Fn(&'a ()) -> &'a ()) {}
+fn accepts_fn_2(_: impl Fn(&'static ()) -> &'static ()) {}
+
+fn main() {
+    let f = late::<'static>;
+    
+    accepts_fn(f); //~ error: `f` doesn't implement `for<'a> Fn(&'a ()) -> &'a ()`
+    accepts_fn_2(f) // works
+    
+    accepts_fn(late) // works
+}
+
+

one potential complication is that we would want a way to specify a generic argument +to a function without having to specify arguments for all previous parameters. i.e. +ideally you could write the following code somehow.

+
fn late<'a, 'b>(_: &'a (), _: &'b ()) {}
+
+fn accepts_fn(_: impl for<'a> Fn(&'a (), &'static ())) {}
+
+fn main() {
+    // a naive implementation would have a `ReInfer` as the subst for `'a` parameter
+    // no longer allowing the FnDef to satisfy the `for<'a> Fn(&'a ()` bound
+    let f = late::<'_, 'static>;
+    accepts_fn(f);
+}
+
+

Maybe we can just special case HIR ty lowering for _/'_ arguments for late bound +parameters somehow and have it not mean the same thing as _ for early bound parameters. +Regardless I think we would need a solution that would allow writing the above code even +if it was done by some new syntax such as having to write late::<k#no_argument, 'static> +(naturally k#no_argument would only make sense as an argument to late bound parameters).

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/effects.html b/effects.html new file mode 100644 index 000000000..046eb92e1 --- /dev/null +++ b/effects.html @@ -0,0 +1,256 @@ + + + + + + Effect checking - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Effects and effect checking

+

Note: all of this describes the implementation of the unstable effects and +const_trait_impl features. None of this implementation is usable or visible from +stable Rust.

+

The implementation of const traits and ~const bounds is a limited effect system. +It is used to allow trait bounds on const fn to be used within the const fn for +method calls. Within the function, in order to know whether a method on a trait +bound is const, we need to know whether there is a ~const bound for the trait. +In order to know whether we can instantiate a ~const bound on a const fn, we +need to know whether there is a const_trait impl for the type and trait being +used (or whether the const fn is used at runtime, then any type implementing the +trait is ok, just like with other bounds).

+

We perform these checks via a const generic boolean that gets attached to all +const fn and const trait. The following sections will explain the desugarings +and the way we perform the checks at call sites.

+

The const generic boolean is inverted to the meaning of const. In the compiler +it is called host, because it enables "host APIs" like static items, network +access, disk access, random numbers and everything else that isn't available in +const contexts. So false means "const", true means "not const" and if it's +a generic parameter, it means "maybe const" (meaning we're in a const fn or const +trait).

+

const fn

+

All const fn have a #[rustc_host] const host: bool generic parameter that is +hidden from users. Any ~const Trait bounds in the generics list or where bounds +of a const fn get converted to Trait<host> + Trait<true> bounds. The Trait<true> +exists so that associated types of the generic param can be used from projections +like <T as Trait>::Assoc, because there are no <T as ~const Trait> projections for now.

+

#[const_trait] traits

+

The #[const_trait] attribute gives the marked trait a #[rustc_host] const host: bool +generic parameter. All functions of the trait "inherit" this generic parameter, just like +they have all the regular generic parameters of the trait. Any ~const Trait super-trait +bounds get desugared to Trait<host> + Trait<true> in order to allow using associated +types and consts of the super traits in the trait declaration. This is necessary, because +<Self as SuperTrait>::Assoc is always <Self as SuperTrait<true>>::Assoc as there is +no <Self as ~const SuperTrait> syntax.

+

typeck performing method and function call checks.

+

When generic parameters are instantiated for any items, the host generic parameter +is always instantiated as an inference variable. This is a special kind of inference var +that is not part of the type or const inference variables, similar to how we have +special inference variables for type variables that we know to be an integer, but not +yet which one. These separate inference variables fall back to true at +the end of typeck (in fallback_effects) to ensure that let _ = some_fn_item_name; +will keep compiling.

+

All actually used (in function calls, casts, or anywhere else) function items, will +have the enforce_context_effects method invoked. +It trivially returns if the function being called has no host generic parameter.

+

In order to error if a non-const function is called in a const context, we have not +yet disabled the const-check logic that happens on MIR, because +enforce_context_effects does not yet perform this check.

+

The function call's host parameter is then equated to the context's host value, +which almost always trivially succeeds, as it was an inference var. If the inference +var has already been bound (since the function item is invoked twice), the second +invocation checks it against the first.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/elasticlunr.min.js b/elasticlunr.min.js new file mode 100644 index 000000000..94b20dd2e --- /dev/null +++ b/elasticlunr.min.js @@ -0,0 +1,10 @@ +/** + * elasticlunr - http://weixsong.github.io + * Lightweight full-text search engine in Javascript for browser search and offline search. - 0.9.5 + * + * Copyright (C) 2017 Oliver Nightingale + * Copyright (C) 2017 Wei Song + * MIT Licensed + * @license + */ +!function(){function e(e){if(null===e||"object"!=typeof e)return e;var t=e.constructor();for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.9.5",lunr=t,t.utils={},t.utils.warn=function(e){return function(t){e.console&&console.warn&&console.warn(t)}}(this),t.utils.toString=function(e){return void 0===e||null===e?"":e.toString()},t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),t=e.pop(),n=e;if("function"!=typeof t)throw new TypeError("last argument must be a function");n.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},t.EventEmitter.prototype.removeListener=function(e,t){if(this.hasHandler(e)){var n=this.events[e].indexOf(t);-1!==n&&(this.events[e].splice(n,1),0==this.events[e].length&&delete this.events[e])}},t.EventEmitter.prototype.emit=function(e){if(this.hasHandler(e)){var t=Array.prototype.slice.call(arguments,1);this.events[e].forEach(function(e){e.apply(void 0,t)},this)}},t.EventEmitter.prototype.hasHandler=function(e){return e in this.events},t.tokenizer=function(e){if(!arguments.length||null===e||void 0===e)return[];if(Array.isArray(e)){var n=e.filter(function(e){return null===e||void 0===e?!1:!0});n=n.map(function(e){return t.utils.toString(e).toLowerCase()});var i=[];return n.forEach(function(e){var n=e.split(t.tokenizer.seperator);i=i.concat(n)},this),i}return e.toString().trim().toLowerCase().split(t.tokenizer.seperator)},t.tokenizer.defaultSeperator=/[\s\-]+/,t.tokenizer.seperator=t.tokenizer.defaultSeperator,t.tokenizer.setSeperator=function(e){null!==e&&void 0!==e&&"object"==typeof e&&(t.tokenizer.seperator=e)},t.tokenizer.resetSeperator=function(){t.tokenizer.seperator=t.tokenizer.defaultSeperator},t.tokenizer.getSeperator=function(){return t.tokenizer.seperator},t.Pipeline=function(){this._queue=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in t.Pipeline.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[n]=e},t.Pipeline.getRegisteredFunction=function(e){return e in t.Pipeline.registeredFunctions!=!0?null:t.Pipeline.registeredFunctions[e]},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.getRegisteredFunction(e);if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._queue.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i+1,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i,0,n)},t.Pipeline.prototype.remove=function(e){var t=this._queue.indexOf(e);-1!==t&&this._queue.splice(t,1)},t.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,i=this._queue.length,o=0;n>o;o++){for(var r=e[o],s=0;i>s&&(r=this._queue[s](r,o,e),void 0!==r&&null!==r);s++);void 0!==r&&null!==r&&t.push(r)}return t},t.Pipeline.prototype.reset=function(){this._queue=[]},t.Pipeline.prototype.get=function(){return this._queue},t.Pipeline.prototype.toJSON=function(){return this._queue.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.DocumentStore,this.index={},this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var e=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,e)},t.Index.prototype.off=function(e,t){return this.eventEmitter.removeListener(e,t)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;n._fields=e.fields,n._ref=e.ref,n.documentStore=t.DocumentStore.load(e.documentStore),n.pipeline=t.Pipeline.load(e.pipeline),n.index={};for(var i in e.index)n.index[i]=t.InvertedIndex.load(e.index[i]);return n},t.Index.prototype.addField=function(e){return this._fields.push(e),this.index[e]=new t.InvertedIndex,this},t.Index.prototype.setRef=function(e){return this._ref=e,this},t.Index.prototype.saveDocument=function(e){return this.documentStore=new t.DocumentStore(e),this},t.Index.prototype.addDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.addDoc(i,e),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));this.documentStore.addFieldLength(i,n,o.length);var r={};o.forEach(function(e){e in r?r[e]+=1:r[e]=1},this);for(var s in r){var u=r[s];u=Math.sqrt(u),this.index[n].addToken(s,{ref:i,tf:u})}},this),n&&this.eventEmitter.emit("add",e,this)}},t.Index.prototype.removeDocByRef=function(e){if(e&&this.documentStore.isDocStored()!==!1&&this.documentStore.hasDoc(e)){var t=this.documentStore.getDoc(e);this.removeDoc(t,!1)}},t.Index.prototype.removeDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.hasDoc(i)&&(this.documentStore.removeDoc(i),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));o.forEach(function(e){this.index[n].removeToken(e,i)},this)},this),n&&this.eventEmitter.emit("remove",e,this))}},t.Index.prototype.updateDoc=function(e,t){var t=void 0===t?!0:t;this.removeDocByRef(e[this._ref],!1),this.addDoc(e,!1),t&&this.eventEmitter.emit("update",e,this)},t.Index.prototype.idf=function(e,t){var n="@"+t+"/"+e;if(Object.prototype.hasOwnProperty.call(this._idfCache,n))return this._idfCache[n];var i=this.index[t].getDocFreq(e),o=1+Math.log(this.documentStore.length/(i+1));return this._idfCache[n]=o,o},t.Index.prototype.getFields=function(){return this._fields.slice()},t.Index.prototype.search=function(e,n){if(!e)return[];e="string"==typeof e?{any:e}:JSON.parse(JSON.stringify(e));var i=null;null!=n&&(i=JSON.stringify(n));for(var o=new t.Configuration(i,this.getFields()).get(),r={},s=Object.keys(e),u=0;u0&&t.push(e);for(var i in n)"docs"!==i&&"df"!==i&&this.expandToken(e+i,t,n[i]);return t},t.InvertedIndex.prototype.toJSON=function(){return{root:this.root}},t.Configuration=function(e,n){var e=e||"";if(void 0==n||null==n)throw new Error("fields should not be null");this.config={};var i;try{i=JSON.parse(e),this.buildUserConfig(i,n)}catch(o){t.utils.warn("user configuration parse failed, will use default configuration"),this.buildDefaultConfig(n)}},t.Configuration.prototype.buildDefaultConfig=function(e){this.reset(),e.forEach(function(e){this.config[e]={boost:1,bool:"OR",expand:!1}},this)},t.Configuration.prototype.buildUserConfig=function(e,n){var i="OR",o=!1;if(this.reset(),"bool"in e&&(i=e.bool||i),"expand"in e&&(o=e.expand||o),"fields"in e)for(var r in e.fields)if(n.indexOf(r)>-1){var s=e.fields[r],u=o;void 0!=s.expand&&(u=s.expand),this.config[r]={boost:s.boost||0===s.boost?s.boost:1,bool:s.bool||i,expand:u}}else t.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(i,o,n)},t.Configuration.prototype.addAllFields2UserConfig=function(e,t,n){n.forEach(function(n){this.config[n]={boost:1,bool:e,expand:t}},this)},t.Configuration.prototype.get=function(){return this.config},t.Configuration.prototype.reset=function(){this.config={}},lunr.SortedSet=function(){this.length=0,this.elements=[]},lunr.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},lunr.SortedSet.prototype.add=function(){var e,t;for(e=0;e1;){if(r===e)return o;e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o]}return r===e?o:-1},lunr.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,i=n-t,o=t+Math.floor(i/2),r=this.elements[o];i>1;)e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o];return r>e?o:e>r?o+1:void 0},lunr.SortedSet.prototype.intersect=function(e){for(var t=new lunr.SortedSet,n=0,i=0,o=this.length,r=e.length,s=this.elements,u=e.elements;;){if(n>o-1||i>r-1)break;s[n]!==u[i]?s[n]u[i]&&i++:(t.add(s[n]),n++,i++)}return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){var t,n,i;this.length>=e.length?(t=this,n=e):(t=e,n=this),i=t.clone();for(var o=0,r=n.toArray();o + + + + + Using external repositories - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Using External Repositories

+

The rust-lang/rust git repository depends on several other repos in the rust-lang organization. +There are three main ways we use dependencies:

+
    +
  1. As a Cargo dependency through crates.io (e.g. rustc-rayon)
  2. +
  3. As a git subtree (e.g. clippy)
  4. +
  5. As a git submodule (e.g. cargo)
  6. +
+

As a general rule, use crates.io for libraries that could be useful for others in the ecosystem; use +subtrees for tools that depend on compiler internals and need to be updated if there are breaking +changes; and use submodules for tools that are independent of the compiler.

+

External Dependencies (subtree)

+

As a developer to this repository, you don't have to treat the following external projects +differently from other crates that are directly in this repo:

+ +

In contrast to submodule dependencies +(see below for those), the subtree dependencies are just regular files and directories which can +be updated in tree. However, if possible, enhancements, bug fixes, etc. specific +to these tools should be filed against the tools directly in their respective +upstream repositories. The exception is that when rustc changes are required to +implement a new tool feature or test, that should happen in one collective rustc PR.

+

Synchronizing a subtree

+

Periodically the changes made to subtree based dependencies need to be synchronized between this +repository and the upstream tool repositories.

+

Subtree synchronizations are typically handled by the respective tool maintainers. Other users +are welcome to submit synchronization PRs, however, in order to do so you will need to modify +your local git installation and follow a very precise set of instructions. +These instructions are documented, along with several useful tips and tricks, in the +syncing subtree changes section in Clippy's Contributing guide. +The instructions are applicable for use with any subtree based tool, just be sure to +use the correct corresponding subtree directory and remote repository.

+

The synchronization process goes in two directions: subtree push and subtree pull.

+

A subtree push takes all the changes that happened to the copy in this repo and creates commits +on the remote repo that match the local changes. Every local +commit that touched the subtree causes a commit on the remote repo, but +is modified to move the files from the specified directory to the tool repo root.

+

A subtree pull takes all changes since the last subtree pull +from the tool repo and adds these commits to the rustc repo along with a merge commit that moves +the tool changes into the specified directory in the Rust repository.

+

It is recommended that you always do a push first and get that merged to the tool master branch. +Then, when you do a pull, the merge works without conflicts. +While it's definitely possible to resolve conflicts during a pull, you may have to redo the conflict +resolution if your PR doesn't get merged fast enough and there are new conflicts. Do not try to +rebase the result of a git subtree pull, rebasing merge commits is a bad idea in general.

+

You always need to specify the -P prefix to the subtree directory and the corresponding remote +repository. If you specify the wrong directory or repository +you'll get very fun merges that try to push the wrong directory to the wrong remote repository. +Luckily you can just abort this without any consequences by throwing away either the pulled commits +in rustc or the pushed branch on the remote and try again. It is usually fairly obvious +that this is happening because you suddenly get thousands of commits that want to be synchronized.

+

Creating a new subtree dependency

+

If you want to create a new subtree dependency from an existing repository, call (from this +repository's root directory!)

+
git subtree add -P src/tools/clippy https://github.com/rust-lang/rust-clippy.git master
+
+

This will create a new commit, which you may not rebase under any circumstances! Delete the commit +and redo the operation if you need to rebase.

+

Now you're done, the src/tools/clippy directory behaves as if Clippy were +part of the rustc monorepo, so no one but you (or others that synchronize +subtrees) actually needs to use git subtree.

+

External Dependencies (submodules)

+

Building Rust will also use external git repositories tracked using git +submodules. The complete list may be found in the .gitmodules file. Some +of these projects are required (like stdarch for the standard library) and +some of them are optional (like src/doc/book).

+

Usage of submodules is discussed more in the Using Git chapter.

+

Some of the submodules are allowed to be in a "broken" state where they +either don't build or their tests don't pass, e.g. the documentation books +like The Rust Reference. Maintainers of these projects will be notified +when the project is in a broken state, and they should fix them as soon +as possible. The current status is tracked on the toolstate website. +More information may be found on the Forge Toolstate chapter. +In practice, it is very rare for documentation to have broken toolstate.

+

Breakage is not allowed in the beta and stable channels, and must be addressed +before the PR is merged. They are also not allowed to be broken on master in +the week leading up to the beta cut.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/favicon.png b/favicon.png new file mode 100644 index 000000000..a5b1aa16c Binary files /dev/null and b/favicon.png differ diff --git a/favicon.svg b/favicon.svg new file mode 100644 index 000000000..90e0ea58b --- /dev/null +++ b/favicon.svg @@ -0,0 +1,22 @@ + + + + + diff --git a/feature-gate-ck.html b/feature-gate-ck.html new file mode 100644 index 000000000..c6b109fd6 --- /dev/null +++ b/feature-gate-ck.html @@ -0,0 +1,205 @@ + + + + + + Feature Gate Checking - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Feature Gate Checking

+

TODO: this chapter #1158

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/feature-gates.html b/feature-gates.html new file mode 100644 index 000000000..d563c9143 --- /dev/null +++ b/feature-gates.html @@ -0,0 +1,262 @@ + + + + + + Feature Gates - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Feature Gates

+

This chapter is intended to provide basic help for adding, removing, and +modifying feature gates.

+

Note that this is specific to language feature gates; library feature gates use a different +mechanism.

+

Adding a feature gate

+

See "Stability in code" in the "Implementing new features" section for instructions.

+

Removing a feature gate

+

To remove a feature gate, follow these steps:

+
    +
  1. +

    Remove the feature gate declaration in rustc_feature/src/unstable.rs. +It will look like this:

    +
    /// description of feature
    +(unstable, $feature_name, "$version", Some($tracking_issue_number))
    +
    +
  2. +
  3. +

    Add a modified version of the feature gate declaration that you just +removed to rustc_feature/src/removed.rs:

    +
    /// description of feature
    +(removed, $old_feature_name, "$version", Some($tracking_issue_number),
    + Some("$why_it_was_removed"))
    +
    +
  4. +
+

Renaming a feature gate

+

To rename a feature gate, follow these steps (the first two are the same steps +to follow when removing a feature gate):

+
    +
  1. +

    Remove the old feature gate declaration in rustc_feature/src/unstable.rs. +It will look like this:

    +
    /// description of feature
    +(unstable, $old_feature_name, "$version", Some($tracking_issue_number))
    +
    +
  2. +
  3. +

    Add a modified version of the old feature gate declaration that you just +removed to rustc_feature/src/removed.rs:

    +
    /// description of feature
    +/// Renamed to `$new_feature_name`
    +(removed, $old_feature_name, "$version", Some($tracking_issue_number),
    + Some("renamed to `$new_feature_name`"))
    +
    +
  4. +
  5. +

    Add a feature gate declaration with the new name to +rustc_feature/src/unstable.rs. It should look very similar to the old +declaration:

    +
    /// description of feature
    +(unstable, $new_feature_name, "$version", Some($tracking_issue_number))
    +
    +
  6. +
+

Stabilizing a feature

+

See "Updating the feature-gate listing" in the "Stabilizing Features" chapter +for instructions. There are additional steps you will need to take beyond just +updating the declaration!

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/fonts/OPEN-SANS-LICENSE.txt b/fonts/OPEN-SANS-LICENSE.txt new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/fonts/OPEN-SANS-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/fonts/SOURCE-CODE-PRO-LICENSE.txt b/fonts/SOURCE-CODE-PRO-LICENSE.txt new file mode 100644 index 000000000..366206f54 --- /dev/null +++ b/fonts/SOURCE-CODE-PRO-LICENSE.txt @@ -0,0 +1,93 @@ +Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/fonts/fonts.css b/fonts/fonts.css new file mode 100644 index 000000000..858efa598 --- /dev/null +++ b/fonts/fonts.css @@ -0,0 +1,100 @@ +/* Open Sans is licensed under the Apache License, Version 2.0. See http://www.apache.org/licenses/LICENSE-2.0 */ +/* Source Code Pro is under the Open Font License. See https://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL */ + +/* open-sans-300 - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 300; + src: local('Open Sans Light'), local('OpenSans-Light'), + url('open-sans-v17-all-charsets-300.woff2') format('woff2'); +} + +/* open-sans-300italic - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: italic; + font-weight: 300; + src: local('Open Sans Light Italic'), local('OpenSans-LightItalic'), + url('open-sans-v17-all-charsets-300italic.woff2') format('woff2'); +} + +/* open-sans-regular - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 400; + src: local('Open Sans Regular'), local('OpenSans-Regular'), + url('open-sans-v17-all-charsets-regular.woff2') format('woff2'); +} + +/* open-sans-italic - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: italic; + font-weight: 400; + src: local('Open Sans Italic'), local('OpenSans-Italic'), + url('open-sans-v17-all-charsets-italic.woff2') format('woff2'); +} + +/* open-sans-600 - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 600; + src: local('Open Sans SemiBold'), local('OpenSans-SemiBold'), + url('open-sans-v17-all-charsets-600.woff2') format('woff2'); +} + +/* open-sans-600italic - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: italic; + font-weight: 600; + src: local('Open Sans SemiBold Italic'), local('OpenSans-SemiBoldItalic'), + url('open-sans-v17-all-charsets-600italic.woff2') format('woff2'); +} + +/* open-sans-700 - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 700; + src: local('Open Sans Bold'), local('OpenSans-Bold'), + url('open-sans-v17-all-charsets-700.woff2') format('woff2'); +} + +/* open-sans-700italic - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: italic; + font-weight: 700; + src: local('Open Sans Bold Italic'), local('OpenSans-BoldItalic'), + url('open-sans-v17-all-charsets-700italic.woff2') format('woff2'); +} + +/* open-sans-800 - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 800; + src: local('Open Sans ExtraBold'), local('OpenSans-ExtraBold'), + url('open-sans-v17-all-charsets-800.woff2') format('woff2'); +} + +/* open-sans-800italic - latin_vietnamese_latin-ext_greek-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Open Sans'; + font-style: italic; + font-weight: 800; + src: local('Open Sans ExtraBold Italic'), local('OpenSans-ExtraBoldItalic'), + url('open-sans-v17-all-charsets-800italic.woff2') format('woff2'); +} + +/* source-code-pro-500 - latin_vietnamese_latin-ext_greek_cyrillic-ext_cyrillic */ +@font-face { + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 500; + src: url('source-code-pro-v11-all-charsets-500.woff2') format('woff2'); +} diff --git a/fonts/open-sans-v17-all-charsets-300.woff2 b/fonts/open-sans-v17-all-charsets-300.woff2 new file mode 100644 index 000000000..9f51be370 Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-300.woff2 differ diff --git a/fonts/open-sans-v17-all-charsets-300italic.woff2 b/fonts/open-sans-v17-all-charsets-300italic.woff2 new file mode 100644 index 000000000..2f5454484 Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-300italic.woff2 differ diff --git a/fonts/open-sans-v17-all-charsets-600.woff2 b/fonts/open-sans-v17-all-charsets-600.woff2 new file mode 100644 index 000000000..f503d558d Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-600.woff2 differ diff --git a/fonts/open-sans-v17-all-charsets-600italic.woff2 b/fonts/open-sans-v17-all-charsets-600italic.woff2 new file mode 100644 index 000000000..c99aabe80 Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-600italic.woff2 differ diff --git a/fonts/open-sans-v17-all-charsets-700.woff2 b/fonts/open-sans-v17-all-charsets-700.woff2 new file mode 100644 index 000000000..421a1ab25 Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-700.woff2 differ diff --git a/fonts/open-sans-v17-all-charsets-700italic.woff2 b/fonts/open-sans-v17-all-charsets-700italic.woff2 new file mode 100644 index 000000000..12ce3d20d Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-700italic.woff2 differ diff --git a/fonts/open-sans-v17-all-charsets-800.woff2 b/fonts/open-sans-v17-all-charsets-800.woff2 new file mode 100644 index 000000000..c94a223b0 Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-800.woff2 differ diff --git a/fonts/open-sans-v17-all-charsets-800italic.woff2 b/fonts/open-sans-v17-all-charsets-800italic.woff2 new file mode 100644 index 000000000..eed7d3c63 Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-800italic.woff2 differ diff --git a/fonts/open-sans-v17-all-charsets-italic.woff2 b/fonts/open-sans-v17-all-charsets-italic.woff2 new file mode 100644 index 000000000..398b68a08 Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-italic.woff2 differ diff --git a/fonts/open-sans-v17-all-charsets-regular.woff2 b/fonts/open-sans-v17-all-charsets-regular.woff2 new file mode 100644 index 000000000..8383e94c6 Binary files /dev/null and b/fonts/open-sans-v17-all-charsets-regular.woff2 differ diff --git a/fonts/source-code-pro-v11-all-charsets-500.woff2 b/fonts/source-code-pro-v11-all-charsets-500.woff2 new file mode 100644 index 000000000..722245682 Binary files /dev/null and b/fonts/source-code-pro-v11-all-charsets-500.woff2 differ diff --git a/fuzzing.html b/fuzzing.html new file mode 100644 index 000000000..8007dccae --- /dev/null +++ b/fuzzing.html @@ -0,0 +1,310 @@ + + + + + + Fuzzing - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Fuzzing

+ +

For the purposes of this guide, fuzzing is any testing methodology that +involves compiling a wide variety of programs in an attempt to uncover bugs in +rustc. Fuzzing is often used to find internal compiler errors (ICEs). Fuzzing +can be beneficial, because it can find bugs before users run into them and +provide small, self-contained programs that make the bug easier to track down. +However, some common mistakes can reduce the helpfulness of fuzzing and end up +making contributors' lives harder. To maximize your positive impact on the Rust +project, please read this guide before reporting fuzzer-generated bugs!

+

Guidelines

+

In a nutshell

+

Please do:

+
    +
  • Ensure the bug is still present on the latest nightly rustc
  • +
  • Include a reasonably minimal, standalone example along with any bug report
  • +
  • Include all of the information requested in the bug report template
  • +
  • Search for existing reports with the same message and query stack
  • +
  • Format the test case with rustfmt, if it maintains the bug
  • +
  • Indicate that the bug was found by fuzzing
  • +
+

Please don't:

+
    +
  • Don't report lots of bugs that use internal features, including but not +limited to custom_mir, lang_items, no_core, and rustc_attrs.
  • +
  • Don't seed your fuzzer with inputs that are known to crash rustc (details +below).
  • +
+

Discussion

+

If you're not sure whether or not an ICE is a duplicate of one that's already +been reported, please go ahead and report it and link to issues you think might +be related. In general, ICEs on the same line but with different query stacks +are usually distinct bugs. For example, #109020 and #109129 +had similar error messages:

+
error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:195:90: Failed to normalize <[closure@src/main.rs:36:25: 36:28] as std::ops::FnOnce<(Emplacable<()>,)>>::Output, maybe try to call `try_normalize_erasing_regions` instead
+
+
error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:195:90: Failed to normalize <() as Project>::Assoc, maybe try to call `try_normalize_erasing_regions` instead
+
+

but different query stacks:

+
query stack during panic:
+#0 [fn_abi_of_instance] computing call ABI of `<[closure@src/main.rs:36:25: 36:28] as core::ops::function::FnOnce<(Emplacable<()>,)>>::call_once - shim(vtable)`
+end of query stack
+
+
query stack during panic:
+#0 [check_mod_attrs] checking attributes in top-level module
+#1 [analysis] running analysis passes on this crate
+end of query stack
+
+

Building a corpus

+

When building a corpus, be sure to avoid collecting tests that are already +known to crash rustc. A fuzzer that is seeded with such tests is more likely to +generate bugs with the same root cause, wasting everyone's time. The simplest +way to avoid this is to loop over each file in the corpus, see if it causes an +ICE, and remove it if so.

+

To build a corpus, you may want to use:

+
    +
  • The rustc/rust-analyzer/clippy test suites (or even source code) --- though avoid +tests that are already known to cause failures, which often begin with comments +like // failure-status: 101 or // known-bug: #NNN.
  • +
  • The already-fixed ICEs in Glacier --- though avoid the unfixed +ones in ices/!
  • +
+

Extra credit

+

Here are a few things you can do to help the Rust project after filing an ICE.

+
    +
  • Bisect the bug to figure out when it was introduced
  • +
  • Fix "distractions": problems with the test case that don't contribute to +triggering the ICE, such as syntax errors or borrow-checking errors
  • +
  • Minimize the test case (see below)
  • +
  • Add the minimal test case to Glacier
  • +
+

Minimization

+

It is helpful to carefully minimize the fuzzer-generated input. When +minimizing, be careful to preserve the original error, and avoid introducing +distracting problems such as syntax, type-checking, or borrow-checking errors.

+

There are some tools that can help with minimization. If you're not sure how +to avoid introducing syntax, type-, and borrow-checking errors while using +these tools, post both the complete and minimized test cases. Generally, +syntax-aware tools give the best results in the least amount of time. +treereduce-rust and picireny are syntax-aware. +halfempty is not, but is generally a high-quality tool.

+

Effective fuzzing

+

When fuzzing rustc, you may want to avoid generating machine code, since this +is mostly done by LLVM. Try --emit=mir instead.

+

A variety of compiler flags can uncover different issues. -Zmir-opt-level=4 +will turn on MIR optimization passes that are not run by default, potentially +uncovering interesting bugs. -Zvalidate-mir can help uncover such bugs.

+

If you're fuzzing a compiler you built, you may want to build it with -C target-cpu=native or even PGO/BOLT to squeeze out a few more executions per +second. Of course, it's best to try multiple build configurations and see +what actually results in superior throughput.

+

You may want to build rustc from source with debug assertions to find +additional bugs, though this is a trade-off: it can slow down fuzzing by +requiring extra work for every execution. To enable debug assertions, add this +to config.toml when compiling rustc:

+
[rust]
+debug-assertions = true
+
+

ICEs that require debug assertions to reproduce should be tagged +requires-debug-assertions.

+

Existing projects

+
    +
  • fuzz-rustc demonstrates how to fuzz rustc with libfuzzer
  • +
  • icemaker runs rustc and other tools on a large number of source +files with a variety of flags to catch ICEs
  • +
  • tree-splicer generates new source files by combining existing +ones while maintaining correct syntax
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/generic_parameters_summary.html b/generic_parameters_summary.html new file mode 100644 index 000000000..b111a51e5 --- /dev/null +++ b/generic_parameters_summary.html @@ -0,0 +1,206 @@ + + + + + + Generic parameter definitions - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Generic parameter definitions

+

This chapter will discuss how rustc tracks what generic parameters are introduced by an item. For example given some struct defined via struct Foo<T> how does rustc track that Foo defines some type parameter T and nothing else?

+

This will not cover how we track generic parameters introduced via for<'a> syntax (i.e. in where clauses or fn types), which is covered elsewhere in the chapter on Binders .

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/getting-started.html b/getting-started.html new file mode 100644 index 000000000..5173d188d --- /dev/null +++ b/getting-started.html @@ -0,0 +1,339 @@ + + + + + + Getting Started - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Getting Started

+

Thank you for your interest in contributing to Rust! There are many ways to +contribute, and we appreciate all of them.

+ +

If this is your first time contributing, the walkthrough chapter can give you a good example of +how a typical contribution would go.

+

This documentation is not intended to be comprehensive; it is meant to be a +quick guide for the most useful things. For more information, see this +chapter on how to build and run the compiler.

+

Asking Questions

+

If you have questions, please make a post on the Rust Zulip server or +internals.rust-lang.org. If you are contributing to Rustup, be aware they are not on +Zulip - you can ask questions in #wg-rustup on Discord. +See the list of teams and working groups and the Community page on the +official website for more resources.

+

As a reminder, all contributors are expected to follow our Code of Conduct.

+

The compiler team (or t-compiler) usually hangs out in Zulip in this +"stream"; it will be easiest to get questions answered there.

+

Please ask questions! A lot of people report feeling that they are "wasting +expert time", but nobody on t-compiler feels this way. Contributors are +important to us.

+

Also, if you feel comfortable, prefer public topics, as this means others can +see the questions and answers, and perhaps even integrate them back into this +guide :)

+

Experts

+

Not all t-compiler members are experts on all parts of rustc; it's a +pretty large project. To find out who could have some expertise on +different parts of the compiler, consult triagebot assign groups. +The sections that start with [assign* in triagebot.toml file. +But also, feel free to ask questions even if you can't figure out who to ping.

+

Another way to find experts for a given part of the compiler is to see who has made recent commits. +For example, to find people who have recently worked on name resolution since the 1.68.2 release, +you could run git shortlog -n 1.68.2.. compiler/rustc_resolve/. Ignore any commits starting with +"Rollup merge" or commits by @bors (see CI contribution procedures for +more information about these commits).

+

Etiquette

+

We do ask that you be mindful to include as much useful information as you can +in your question, but we recognize this can be hard if you are unfamiliar with +contributing to Rust.

+

Just pinging someone without providing any context can be a bit annoying and +just create noise, so we ask that you be mindful of the fact that the +t-compiler folks get a lot of pings in a day.

+

What should I work on?

+

The Rust project is quite large and it can be difficult to know which parts of the project need +help, or are a good starting place for beginners. Here are some suggested starting places.

+

Easy or mentored issues

+

If you're looking for somewhere to start, check out the following issue +search. See the Triage for an explanation of these labels. You can also try +filtering the search to areas you're interested in. For example:

+
    +
  • repo:rust-lang/rust-clippy will only show clippy issues
  • +
  • label:T-compiler will only show issues related to the compiler
  • +
  • label:A-diagnostics will only show diagnostic issues
  • +
+

Not all important or beginner work has issue labels. +See below for how to find work that isn't labelled.

+

Recurring work

+

Some work is too large to be done by a single person. In this case, it's common to have "Tracking +issues" to co-ordinate the work between contributors. Here are some example tracking issues where +it's easy to pick up work without a large time commitment:

+ +

If you find more recurring work, please feel free to add it here!

+

Clippy issues

+

The Clippy project has spent a long time making its contribution process as friendly to newcomers +as possible. Consider working on it first to get familiar with the process and the compiler +internals.

+

See the Clippy contribution guide for instructions on getting started.

+

Diagnostic issues

+

Many diagnostic issues are self-contained and don't need detailed background knowledge of the +compiler. You can see a list of diagnostic issues here.

+

Picking up abandoned pull requests

+

Sometimes, contributors send a pull request, but later find out that they don't have enough +time to work on it, or they simply are not interested in it anymore. Such PRs are often +eventually closed and they receive the S-inactive label. You could try to examine some of +these PRs and pick up the work. You can find the list of such PRs here.

+

If the PR has been implemented in some other way in the meantime, the S-inactive label +should be removed from it. If not, and it seems that there is still interest in the change, +you can try to rebase the pull request on top of the latest master branch and send a new +pull request, continuing the work on the feature.

+

Contributing to std (standard library)

+

See std-dev-guide.

+

Contributing code to other Rust projects

+

There are a bunch of other projects that you can contribute to outside of the +rust-lang/rust repo, including cargo, miri, rustup, and many others.

+

These repos might have their own contributing guidelines and procedures. Many +of them are owned by working groups. For more info, see the documentation in those repos' READMEs.

+

Other ways to contribute

+

There are a bunch of other ways you can contribute, especially if you don't +feel comfortable jumping straight into the large rust-lang/rust codebase.

+

The following tasks are doable without much background knowledge but are +incredibly helpful:

+
    +
  • Cleanup crew: find minimal reproductions of ICEs, bisect +regressions, etc. This is a way of helping that saves a ton of time for +others to fix an error later.
  • +
  • Writing documentation: if you are feeling a bit more intrepid, you could try +to read a part of the code and write doc comments for it. This will help you +to learn some part of the compiler while also producing a useful artifact!
  • +
  • Triaging issues: categorizing, replicating, and minimizing issues is very helpful to the Rust maintainers.
  • +
  • Working groups: there are a bunch of working groups on a wide variety +of rust-related things.
  • +
  • Answer questions in the Get Help! channels on the Rust Discord +server, on users.rust-lang.org, or on +StackOverflow.
  • +
  • Participate in the RFC process.
  • +
  • Find a requested community library, build it, and publish +it to Crates.io. Easier said than done, but very, very +valuable!
  • +
+

Cloning and Building

+

See "How to build and run the compiler".

+

Contributor Procedures

+

This section has moved to the "Contribution Procedures" chapter.

+

Other Resources

+

This section has moved to the "About this guide" chapter.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/git.html b/git.html new file mode 100644 index 000000000..000fedf36 --- /dev/null +++ b/git.html @@ -0,0 +1,679 @@ + + + + + + Using Git - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Using Git

+ +

The Rust project uses Git to manage its source code. In order to +contribute, you'll need some familiarity with its features so that your changes +can be incorporated into the compiler.

+

The goal of this page is to cover some of the more common questions and +problems new contributors face. Although some Git basics will be covered here, +if you find that this is still a little too fast for you, it might make sense +to first read some introductions to Git, such as the Beginner and Getting +started sections of this tutorial from Atlassian. GitHub also +provides documentation and guides for beginners, or you can consult the +more in depth book from Git.

+

This guide is incomplete. If you run into trouble with git that this page doesn't help with, +please open an issue so we can document how to fix it.

+

Prerequisites

+

We'll assume that you've installed Git, forked rust-lang/rust, and cloned the +forked repo to your PC. We'll use the command line interface to interact +with Git; there are also a number of GUIs and IDE integrations that can +generally do the same things.

+

If you've cloned your fork, then you will be able to reference it with origin +in your local repo. It may be helpful to also set up a remote for the official +rust-lang/rust repo via

+
git remote add upstream https://github.com/rust-lang/rust.git
+
+

if you're using HTTPS, or

+
git remote add upstream git@github.com:rust-lang/rust.git
+
+

if you're using SSH.

+

NOTE: This page is dedicated to workflows for rust-lang/rust, but will likely be +useful when contributing to other repositories in the Rust project.

+

Standard Process

+

Below is the normal procedure that you're likely to use for most minor changes +and PRs:

+
    +
  1. Ensure that you're making your changes on top of master: +git checkout master.
  2. +
  3. Get the latest changes from the Rust repo: git pull upstream master --ff-only. +(see No-Merge Policy for more info about this).
  4. +
  5. Make a new branch for your change: git checkout -b issue-12345-fix.
  6. +
  7. Make some changes to the repo and test them.
  8. +
  9. Stage your changes via git add src/changed/file.rs src/another/change.rs +and then commit them with git commit. Of course, making intermediate commits +may be a good idea as well. Avoid git add ., as it makes it too easy to +unintentionally commit changes that should not be committed, such as submodule +updates. You can use git status to check if there are any files you forgot +to stage.
  10. +
  11. Push your changes to your fork: git push --set-upstream origin issue-12345-fix +(After adding commits, you can use git push and after rebasing or +pulling-and-rebasing, you can use git push --force-with-lease).
  12. +
  13. Open a PR from your fork to rust-lang/rust's master branch.
  14. +
+

If you end up needing to rebase and are hitting conflicts, see Rebasing. +If you want to track upstream while working on long-running feature/issue, see +Keeping things up to date.

+

If your reviewer requests changes, the procedure for those changes looks much +the same, with some steps skipped:

+
    +
  1. Ensure that you're making changes to the most recent version of your code: +git checkout issue-12345-fix.
  2. +
  3. Make, stage, and commit your additional changes just like before.
  4. +
  5. Push those changes to your fork: git push.
  6. +
+

Troubleshooting git issues

+

You don't need to clone rust-lang/rust from scratch if it's out of date! +Even if you think you've messed it up beyond repair, there are ways to fix +the git state that don't require downloading the whole repository again. +Here are some common issues you might run into:

+

I made a merge commit by accident.

+

Git has two ways to update your branch with the newest changes: merging and rebasing. +Rust uses rebasing. If you make a merge commit, it's not too hard to fix: +git rebase -i upstream/master.

+

See Rebasing for more about rebasing.

+

I deleted my fork on GitHub!

+

This is not a problem from git's perspective. If you run git remote -v, +it will say something like this:

+
$ git remote -v
+origin  git@github.com:jyn514/rust.git (fetch)
+origin  git@github.com:jyn514/rust.git (push)
+upstream        https://github.com/rust-lang/rust (fetch)
+upstream        https://github.com/rust-lang/rust (fetch)
+
+

If you renamed your fork, you can change the URL like this:

+
git remote set-url origin <URL>
+
+

where the <URL> is your new fork.

+

I changed a submodule by accident

+

Usually people notice this when rustbot posts a comment on github that cargo has been modified:

+

rustbot submodule comment

+

You might also notice conflicts in the web UI:

+

conflict in src/tools/cargo

+

The most common cause is that you rebased after a change and ran git add . without first running +x to update the submodules. Alternatively, you might have run cargo fmt instead of x fmt +and modified files in a submodule, then committed the changes.

+

To fix it, do the following things:

+
    +
  1. See which commit has the accidental changes: git log --stat -n1 src/tools/cargo
  2. +
  3. Revert the changes to that commit: git checkout <my-commit>~ src/tools/cargo. Type ~ +literally but replace <my-commit> with the output from step 1.
  4. +
  5. Tell git to commit the changes: git commit --fixup <my-commit>
  6. +
  7. Repeat steps 1-3 for all the submodules you modified. +
      +
    • If you modified the submodule in several different commits, you will need to repeat steps 1-3 +for each commit you modified. You'll know when to stop when the git log command shows a commit +that's not authored by you.
    • +
    +
  8. +
  9. Squash your changes into the existing commits: git rebase --autosquash -i upstream/master
  10. +
  11. Push your changes.
  12. +
+

I see "error: cannot rebase" when I try to rebase

+

These are two common errors to see when rebasing:

+
error: cannot rebase: Your index contains uncommitted changes.
+error: Please commit or stash them.
+
+
error: cannot rebase: You have unstaged changes.
+error: Please commit or stash them.
+
+

(See https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F#_the_three_states for the difference between the two.)

+

This means you have made changes since the last time you made a commit. To be able to rebase, either +commit your changes, or make a temporary commit called a "stash" to have them still not be committed +when you finish rebasing. You may want to configure git to make this "stash" automatically, which +will prevent the "cannot rebase" error in nearly all cases:

+
git config --global rebase.autostash true
+
+

See https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning for more info about stashing.

+

I see 'Untracked Files: src/stdarch'?

+

This is left over from the move to the library/ directory. +Unfortunately, git rebase does not follow renames for submodules, so you +have to delete the directory yourself:

+
rm -r src/stdarch
+
+

I see <<< HEAD?

+

You were probably in the middle of a rebase or merge conflict. See +Conflicts for how to fix the conflict. If you don't care about the changes +and just want to get a clean copy of the repository back, you can use git reset:

+
# WARNING: this throws out any local changes you've made! Consider resolving the conflicts instead.
+git reset --hard master
+
+

failed to push some refs

+

git push will not work properly and say something like this:

+
 ! [rejected]        issue-xxxxx -> issue-xxxxx (non-fast-forward)
+error: failed to push some refs to 'https://github.com/username/rust.git'
+hint: Updates were rejected because the tip of your current branch is behind
+hint: its remote counterpart. Integrate the remote changes (e.g.
+hint: 'git pull ...') before pushing again.
+hint: See the 'Note about fast-forwards' in 'git push --help' for details.
+
+

The advice this gives is incorrect! Because of Rust's +"no-merge" policy the merge commit created by git pull +will not be allowed in the final PR, in addition to defeating the point of the +rebase! Use git push --force-with-lease instead.

+

Git is trying to rebase commits I didn't write?

+

If you see many commits in your rebase list, or merge commits, or commits by other people that you +didn't write, it likely means you're trying to rebase over the wrong branch. For example, you may +have a rust-lang/rust remote upstream, but ran git rebase origin/master instead of git rebase upstream/master. The fix is to abort the rebase and use the correct branch instead:

+
git rebase --abort
+git rebase -i upstream/master
+
+
Click here to see an example of rebasing over the wrong branch +

Interactive rebase over the wrong branch

+
+

Quick note about submodules

+

When updating your local repository with git pull, you may notice that sometimes +Git says you have modified some files that you have never edited. For example, +running git status gives you something like (note the new commits mention):

+
On branch master
+Your branch is up to date with 'origin/master'.
+
+Changes not staged for commit:
+  (use "git add <file>..." to update what will be committed)
+  (use "git restore <file>..." to discard changes in working directory)
+	modified:   src/llvm-project (new commits)
+	modified:   src/tools/cargo (new commits)
+
+no changes added to commit (use "git add" and/or "git commit -a")
+
+

These changes are not changes to files: they are changes to submodules (more on this +later). To get rid of those, run ./x --help, which will automatically update +the submodules.

+

Some submodules are not actually needed; for example, src/llvm-project doesn't need to be checked +out if you're using download-ci-llvm. To avoid having to keep fetching its history, you can use +git submodule deinit -f src/llvm-project, which will also avoid it showing as modified again.

+

Rebasing and Conflicts

+

When you edit your code locally, you are making changes to the version of +rust-lang/rust that existed when you created your feature branch. As such, when +you submit your PR it is possible that some of the changes that have been made +to rust-lang/rust since then are in conflict with the changes you've made. +When this happens, you need to resolve the conflicts before your changes can be +merged. To do that, you need to rebase your work on top of rust-lang/rust.

+

Rebasing

+

To rebase your feature branch on top of the newest version of the master branch +of rust-lang/rust, checkout your branch, and then run this command:

+
git pull --rebase https://github.com/rust-lang/rust.git master
+
+
+

If you are met with the following error:

+
error: cannot pull with rebase: Your index contains uncommitted changes.
+error: please commit or stash them.
+
+

it means that you have some uncommitted work in your working tree. In that +case, run git stash before rebasing, and then git stash pop after you +have rebased and fixed all conflicts.

+
+

When you rebase a branch on master, all the changes on your branch are +reapplied to the most recent version of master. In other words, Git tries to +pretend that the changes you made to the old version of master were instead +made to the new version of master. During this process, you should expect to +encounter at least one "rebase conflict." This happens when Git's attempt to +reapply the changes fails because your changes conflicted with other changes +that have been made. You can tell that this happened because you'll see +lines in the output that look like

+
CONFLICT (content): Merge conflict in file.rs
+
+

When you open these files, you'll see sections of the form

+
<<<<<<< HEAD
+Original code
+=======
+Your code
+>>>>>>> 8fbf656... Commit fixes 12345
+
+

This represents the lines in the file that Git could not figure out how to +rebase. The section between <<<<<<< HEAD and ======= has the code from +master, while the other side has your version of the code. You'll need to +decide how to deal with the conflict. You may want to keep your changes, +keep the changes on master, or combine the two.

+

Generally, resolving the conflict consists of two steps: First, fix the +particular conflict. Edit the file to make the changes you want and remove the +<<<<<<<, ======= and >>>>>>> lines in the process. Second, check the +surrounding code. If there was a conflict, its likely there are some logical +errors lying around too! It's a good idea to run x check here to make sure +there are no glaring errors.

+

Once you're all done fixing the conflicts, you need to stage the files that had +conflicts in them via git add. Afterwards, run git rebase --continue to let +Git know that you've resolved the conflicts and it should finish the rebase.

+

Once the rebase has succeeded, you'll want to update the associated branch on +your fork with git push --force-with-lease.

+

Keeping things up to date

+

The above section on Rebasing is a specific +guide on rebasing work and dealing with merge conflicts. +Here is some general advice about how to keep your local repo +up-to-date with upstream changes:

+

Using git pull upstream master while on your local master branch regularly +will keep it up-to-date. You will also want to rebase your feature branches +up-to-date as well. After pulling, you can checkout the feature branches +and rebase them:

+
git checkout master
+git pull upstream master --ff-only # to make certain there are no merge commits
+git rebase master feature_branch
+git push --force-with-lease # (set origin to be the same as local)
+
+

To avoid merges as per the No-Merge Policy, you may want to use +git config pull.ff only (this will apply the config only to the local repo) +to ensure that Git doesn't create merge commits when git pulling, without +needing to pass --ff-only or --rebase every time.

+

You can also git push --force-with-lease from master to keep your fork's master in sync with +upstream.

+

Advanced Rebasing

+

Squash your commits

+

If your branch contains multiple consecutive rewrites of the same code, or if +the rebase conflicts are extremely severe, you can use +git rebase --interactive master to gain more control over the process. This +allows you to choose to skip commits, edit the commits that you do not skip, +change the order in which they are applied, or "squash" them into each other.

+

Alternatively, you can sacrifice the commit history like this:

+
# squash all the changes into one commit so you only have to worry about conflicts once
+git rebase -i $(git merge-base master HEAD)  # and squash all changes along the way
+git rebase master
+# fix all merge conflicts
+git rebase --continue
+
+

"Squashing" commits into each other causes them to be merged into a single +commit. Both the upside and downside of this is that it simplifies the history. +On the one hand, you lose track of the steps in which changes were made, but +the history becomes easier to work with.

+

You also may want to squash just the last few commits together, possibly +because they only represent "fixups" and not real changes. For example, +git rebase --interactive HEAD~2 will allow you to edit the two commits only.

+

git range-diff

+

After completing a rebase, and before pushing up your changes, you may want to +review the changes between your old branch and your new one. You can do that +with git range-diff master @{upstream} HEAD.

+

The first argument to range-diff, master in this case, is the base revision +that you're comparing your old and new branch against. The second argument is +the old version of your branch; in this case, @upstream means the version that +you've pushed to GitHub, which is the same as what people will see in your pull +request. Finally, the third argument to range-diff is the new version of +your branch; in this case, it is HEAD, which is the commit that is currently +checked-out in your local repo.

+

Note that you can also use the equivalent, abbreviated form git range-diff master @{u} HEAD.

+

Unlike in regular Git diffs, you'll see a - or + next to another - or + +in the range-diff output. The marker on the left indicates a change between the +old branch and the new branch, and the marker on the right indicates a change +you've committed. So, you can think of a range-diff as a "diff of diffs" since +it shows you the differences between your old diff and your new diff.

+

Here's an example of git range-diff output (taken from Git's +docs):

+
-:  ------- > 1:  0ddba11 Prepare for the inevitable!
+1:  c0debee = 2:  cab005e Add a helpful message at the start
+2:  f00dbal ! 3:  decafe1 Describe a bug
+    @@ -1,3 +1,3 @@
+     Author: A U Thor <author@example.com>
+
+    -TODO: Describe a bug
+    +Describe a bug
+    @@ -324,5 +324,6
+      This is expected.
+
+    -+What is unexpected is that it will also crash.
+    ++Unexpectedly, it also crashes. This is a bug, and the jury is
+    ++still out there how to fix it best. See ticket #314 for details.
+
+      Contact
+3:  bedead < -:  ------- TO-UNDO
+
+

(Note that git range-diff output in your terminal will probably be easier to +read than in this example because it will have colors.)

+

Another feature of git range-diff is that, unlike git diff, it will also +diff commit messages. This feature can be useful when amending several commit +messages so you can make sure you changed the right parts.

+

git range-diff is a very useful command, but note that it can take some time +to get used to its output format. You may also find Git's documentation on the +command useful, especially their "Examples" section.

+

No-Merge Policy

+

The rust-lang/rust repo uses what is known as a "rebase workflow." This means +that merge commits in PRs are not accepted. As a result, if you are running +git merge locally, chances are good that you should be rebasing instead. Of +course, this is not always true; if your merge will just be a fast-forward, +like the merges that git pull usually performs, then no merge commit is +created and you have nothing to worry about. Running git config merge.ff only +(this will apply the config to the local repo) +once will ensure that all the merges you perform are of this type, so that you +cannot make a mistake.

+

There are a number of reasons for this decision and like all others, it is a +tradeoff. The main advantage is the generally linear commit history. This +greatly simplifies bisecting and makes the history and commit log much easier +to follow and understand.

+

Tips for reviewing

+

NOTE: This section is for reviewing PRs, not authoring them.

+

Hiding whitespace

+

Github has a button for disabling whitespace changes that may be useful. +You can also use git diff -w origin/master to view changes locally.

+

hide whitespace

+

Fetching PRs

+

To checkout PRs locally, you can use git fetch upstream pull/NNNNN/head && git checkout FETCH_HEAD.

+

You can also use github's cli tool. Github shows a button on PRs where you can copy-paste the +command to check it out locally. See https://cli.github.com/ for more info.

+

gh suggestion

+

Moving large sections of code

+

Git and Github's default diff view for large moves within a file is quite poor; it will show each +line as deleted and each line as added, forcing you to compare each line yourself. Git has an option +to show moved lines in a different color:

+
git log -p --color-moved=dimmed-zebra --color-moved-ws=allow-indentation-change
+
+

See the docs for --color-moved for more info.

+

range-diff

+

See the relevant section for PR authors. This can be useful for comparing code +that was force-pushed to make sure there are no unexpected changes.

+

Ignoring changes to specific files

+

Many large files in the repo are autogenerated. To view a diff that ignores changes to those files, +you can use the following syntax (e.g. Cargo.lock):

+
git log -p ':!Cargo.lock'
+
+

Arbitrary patterns are supported (e.g. :!compiler/*). Patterns use the same syntax as +.gitignore, with : prepended to indicate a pattern.

+

Git submodules

+

NOTE: submodules are a nice thing to know about, but it isn't an absolute +prerequisite to contribute to rustc. If you are using Git for the first time, +you might want to get used to the main concepts of Git before reading this section.

+

The rust-lang/rust repository uses Git submodules as a way to use other +Rust projects from within the rust repo. Examples include Rust's fork of +llvm-project, cargo and libraries like stdarch and backtrace.

+

Those projects are developed and maintained in an separate Git (and GitHub) +repository, and they have their own Git history/commits, issue tracker and PRs. +Submodules allow us to create some sort of embedded sub-repository inside the +rust repository and use them like they were directories in the rust repository.

+

Take llvm-project for example. llvm-project is maintained in the rust-lang/llvm-project +repository, but it is used in rust-lang/rust by the compiler for code generation and +optimization. We bring it in rust as a submodule, in the src/llvm-project folder.

+

The contents of submodules are ignored by Git: submodules are in some sense isolated +from the rest of the repository. However, if you try to cd src/llvm-project and then +run git status:

+
HEAD detached at 9567f08afc943
+nothing to commit, working tree clean
+
+

As far as git is concerned, you are no longer in the rust repo, but in the llvm-project repo. +You will notice that we are in "detached HEAD" state, i.e. not on a branch but on a +particular commit.

+

This is because, like any dependency, we want to be able to control which version to use. +Submodules allow us to do just that: every submodule is "pinned" to a certain +commit, which doesn't change unless modified manually. If you use git checkout <commit> +in the llvm-project directory and go back to the rust directory, you can stage this +change like any other, e.g. by running git add src/llvm-project. (Note that if +you don't stage the change to commit, then you run the risk that running +x will just undo your change by switching back to the previous commit when +it automatically "updates" the submodules.)

+

This version selection is usually done by the maintainers of the project, and +looks like this.

+

Git submodules take some time to get used to, so don't worry if it isn't perfectly +clear yet. You will rarely have to use them directly and, again, you don't need +to know everything about submodules to contribute to Rust. Just know that they +exist and that they correspond to some sort of embedded subrepository dependency +that Git can nicely and fairly conveniently handle for us.

+

Hard-resetting submodules

+

Sometimes you might run into (when you run git status)

+
Changes not staged for commit:
+  (use "git add <file>..." to update what will be committed)
+  (use "git restore <file>..." to discard changes in working directory)
+  (commit or discard the untracked or modified content in submodules)
+        modified:   src/llvm-project (new commits, modified content)
+
+

and when you try to run git submodule update it breaks horribly with errors like

+
error: RPC failed; curl 92 HTTP/2 stream 7 was not closed cleanly: CANCEL (err 8)
+error: 2782 bytes of body are still expected
+fetch-pack: unexpected disconnect while reading sideband packet
+fatal: early EOF
+fatal: fetch-pack: invalid index-pack output
+fatal: Fetched in submodule path 'src/llvm-project', but it did not contain 5a5152f653959d14d68613a3a8a033fb65eec021. Direct fetching of that commit failed.
+
+

If you see (new commits, modified content) you can run

+
$ git submodule foreach git reset --hard
+
+

and then try git submodule update again.

+

Ignoring commits during git blame

+

Some commits contain large reformatting changes that don't otherwise change functionality. They can +be instructed to be ignored by git blame through +.git-blame-ignore-revs:

+
    +
  1. Configure git blame to use .git-blame-ignore-revs as the list of commits to ignore: git config blame.ignorerevsfile .git-blame-ignore-revs
  2. +
  3. Add suitable commits that you wish to be ignored by git blame.
  4. +
+

Please include a comment for the commit that you add to .git-blame-ignore-revs so people can +easily figure out why a commit is ignored.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/guides/editions.html b/guides/editions.html new file mode 100644 index 000000000..5ef826734 --- /dev/null +++ b/guides/editions.html @@ -0,0 +1,476 @@ + + + + + + Editions - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Editions

+ +

This chapter gives an overview of how Edition support works in rustc. +This assumes that you are familiar with what Editions are (see the Edition Guide).

+

Edition definition

+

The --edition CLI flag specifies the edition to use for a crate. +This can be accessed from Session::edition. +There are convenience functions like Session::at_least_rust_2021 for checking the crate's +edition, though you should be careful about whether you check the global session or the span, see +Edition hygiene below.

+

As an alternative to the at_least_rust_20xx convenience methods, the Edition type also +supports comparisons for doing range checks, such as span.edition() >= Edition::Edition2021.

+

Adding a new edition

+

Adding a new edition mainly involves adding a variant to the Edition enum and then fixing +everything that is broken. See #94461 for an +example.

+

Features and Edition stability

+

The Edition enum defines whether or not an edition is stable. +If it is not stable, then the -Zunstable-options CLI option must be passed to enable it.

+

When adding a new feature, there are two options you can choose for how to handle stability with a +future edition:

+
    +
  • Just check the edition of the span like span.at_least_rust_20xx() (see Edition hygiene) or the +Session::edition. This will implicitly depend on the stability of the edition itself to +indicate that your feature is available.
  • +
  • Place your new behavior behind a feature gate.
  • +
+

It may be sufficient to only check the current edition for relatively simple changes. +However, for larger language changes, you should consider creating a feature gate. +There are several benefits to using a feature gate:

+
    +
  • A feature gate makes it easier to work on and experiment with a new feature.
  • +
  • It makes the intent clear when the #![feature(…)] attribute is used that your new feature is +being enabled.
  • +
  • It makes testing of editions easier so that features that are not yet complete do not interfere +with testing of edition-specific features that are complete and ready.
  • +
  • It decouples the feature from an edition, which makes it easier for the team to make a deliberate +decision of whether or not a feature should be added to the next edition when the feature is +ready.
  • +
+

When a feature is complete and ready, the feature gate can be removed (and the code should just +check the span or Session edition to determine if it is enabled).

+

There are a few different options for doing feature checks:

+
    +
  • +

    For highly experimental features, that may or may not be involved in an edition, they can +implement regular feature gates like tcx.features().my_feature, and ignore editions for the time +being.

    +
  • +
  • +

    For experimental features that might be involved in an edition, they should implement gates with +tcx.features().my_feature && span.at_least_rust_20xx(). +This requires the user to still specify #![feature(my_feature)], to avoid disrupting testing of +other edition features which are ready and have been accepted within the edition.

    +
  • +
  • +

    For experimental features that have graduated to definitely be part of an edition, +they should implement gates with tcx.features().my_feature || span.at_least_rust_20xx(), +or just remove the feature check altogether and just check span.at_least_rust_20xx().

    +
  • +
+

If you need to do the feature gating in multiple places, consider placing the check in a single +function so that there will only be a single place to update. For example:

+
// An example from Edition 2021 disjoint closure captures.
+
+fn enable_precise_capture(tcx: TyCtxt<'_>, span: Span) -> bool {
+    tcx.features().capture_disjoint_fields || span.rust_2021()
+}
+
+

See Lints and stability below for more information about how lints handle +stability.

+

Edition parsing

+

For the most part, the lexer is edition-agnostic. +Within StringReader, tokens can be modified based on edition-specific behavior. +For example, C-String literals like c"foo" are split into multiple tokens in editions before 2021. +This is also where things like reserved prefixes are handled for the 2021 edition.

+

Edition-specific parsing is relatively rare. One example is async fn which checks the span of the +token to determine if it is the 2015 edition, and emits an error in that case. +This can only be done if the syntax was already invalid.

+

If you need to do edition checking in the parser, you will normally want to look at the edition of +the token, see Edition hygiene. +In some rare cases you may instead need to check the global edition from ParseSess::edition.

+

Most edition-specific parsing behavior is handled with migration lints instead of in the parser. +This is appropriate when there is a change in syntax (as opposed to new syntax). +This allows the old syntax to continue to work on previous editions. +The lint then checks for the change in behavior. +On older editions, the lint pass should emit the migration lint to help with migrating to new +editions. +On newer editions, your code should emit a hard error with emit_err instead. +For example, the deprecated start...end pattern syntax emits the +ellipsis_inclusive_range_patterns lint on editions before 2021, and in 2021 is an hard error via +the emit_err method.

+

Keywords

+

New keywords can be introduced across an edition boundary. +This is implemented by functions like Symbol::is_used_keyword_conditional, which rely on the +ordering of how the keywords are defined.

+

When new keywords are introduced, the keyword_idents lint should be updated so that automatic +migrations can transition code that might be using the keyword as an identifier (see +KeywordIdents). +An alternative to consider is to implement the keyword as a weak keyword if the position it is used +is sufficient to distinguish it.

+

An additional option to consider is the k# prefix which was introduced in RFC 3101. +This allows the use of a keyword in editions before the edition where the keyword is introduced. +This is currently not implemented.

+

Edition hygiene

+

Spans are marked with the edition of the crate that the span came from. +See Macro hygiene in the Edition Guide for a user-centric description of what this means.

+

You should normally use the edition from the token span instead of looking at the global Session +edition. +For example, use span.edition().at_least_rust_2021() instead of sess.at_least_rust_2021(). +This helps ensure that macros behave correctly when used across crates.

+

Lints

+

Lints support a few different options for interacting with editions. +Lints can be future incompatible edition migration lints, which are used to support +migrations to newer editions. +Alternatively, lints can be edition-specific, where they change their +default level starting in a specific edition.

+

Migration lints

+

Migration lints are used to migrate projects from one edition to the next. +They are implemented with a MachineApplicable suggestion which +will rewrite code so that it will successfully compile in both the previous and the next +edition. +For example, the keyword_idents lint will take identifiers that conflict with a new keyword to +use the raw identifier syntax to avoid the conflict (for example changing async to r#async).

+

Migration lints must be declared with the FutureIncompatibilityReason::EditionError or +FutureIncompatibilityReason::EditionSemanticsChange future-incompatible +option in the lint declaration:

+
declare_lint! {
+    pub KEYWORD_IDENTS,
+    Allow,
+    "detects edition keywords being used as an identifier",
+    @future_incompatible = FutureIncompatibleInfo {
+        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
+        reference: "issue #49716 <https://github.com/rust-lang/rust/issues/49716>",
+    };
+}
+
+

When declared like this, the lint is automatically added to the appropriate +rust-20xx-compatibility lint group. +When a user runs cargo fix --edition, cargo will pass the --force-warn rust-20xx-compatibility +flag to force all of these lints to appear during the edition migration. +Cargo also passes --cap-lints=allow so that no other lints interfere with the edition migration.

+

Migration lints can be either Allow or Warn by default. +If it is Allow, users usually won't see this warning unless they are doing an edition migration +manually or there is a problem during the migration. +Most migration lints are Allow.

+

If it is Warn by default, users on all editions will see this warning. +Only use Warn if you think it is important for everyone to be aware of the change, and to +encourage people to update their code on all editions. +Beware that new warn-by-default lint that hit many projects can be very disruptive and frustrating +for users. +You may consider switching an Allow to Warn several years after the edition stabilizes. +This will only show up for the relatively small number of stragglers who have not updated to the new +edition.

+

Edition-specific lints

+

Lints can be marked so that they have a different level starting in a specific edition. +In the lint declaration, use the @edition marker:

+
declare_lint! {
+    pub SOME_LINT_NAME,
+    Allow,
+    "my lint description",
+    @edition Edition2024 => Warn;
+}
+
+

Here, SOME_LINT_NAME defaults to Allow on all editions before 2024, and then becomes Warn +afterwards.

+

This should generally be used sparingly, as there are other options:

+
    +
  • +

    Small impact stylistic changes unrelated to an edition can just make the lint Warn on all +editions. If you want people to adopt a different way to write things, then go ahead and commit to +having it show up for all projects.

    +

    Beware that if a new warn-by-default lint hits many projects, it can be very disruptive and +frustrating for users.

    +
  • +
  • +

    Change the new style to be a hard error in the new edition, and use a migration lint to +automatically convert projects to the new style. For example, +ellipsis_inclusive_range_patterns is a hard error in 2021, and warns in all previous editions.

    +

    Beware that these cannot be added after the edition stabilizes.

    +
  • +
  • +

    Migration lints can also change over time. +For example, the migration lint can start out as Allow by default. +For people performing the migration, they will automatically get updated to the new code. +Then, after some years, the lint can be made to Warn in previous editions.

    +

    For example anonymous_parameters was a 2018 Edition migration lint (and a hard-error in 2018) +that was Allow by default in previous editions. +Then, three years later, it was changed to Warn for all previous editions, so that all users got +a warning that the style was being phased out. +If this was a warning from the start, it would have impacted many projects and be very disruptive. +By making it part of the edition, most users eventually updated to the new edition and were +handled by the migration. +Switching to Warn only impacted a few stragglers who did not update.

    +
  • +
+

Lints and stability

+

Lints can be marked as being unstable, which can be helpful when developing a new edition feature, +and you want to test out a migration lint. +The feature gate can be specified in the lint's declaration like this:

+
declare_lint! {
+    pub SOME_LINT_NAME,
+    Allow,
+    "my cool lint",
+    @feature_gate = sym::my_feature_name;
+}
+
+

Then, the lint will only fire if the user has the appropriate #![feature(my_feature_name)]. +Just beware that when it comes time to do crater runs testing the migration that the feature gate +will need to be removed.

+

Alternatively, you can implement an allow-by-default migration lint for an upcoming unstable +edition without a feature gate. +Although users may technically be able to enable the lint before the edition is stabilized, most +will not notice the new lint exists, and it should not disrupt anything or cause any breakage.

+

Idiom lints

+

In the 2018 edition, there was a concept of "idiom lints" under the rust-2018-idioms lint group. +The concept was to have new idiomatic styles under a different lint group separate from the forced +migrations under the rust-2018-compatibility lint group, giving some flexibility as to how people +opt-in to certain edition changes.

+

Overall this approach did not seem to work very well, +and it is unlikely that we will use the idiom groups in the future.

+

Standard library changes

+

Preludes

+

Each edition comes with a specific prelude of the standard library. +These are implemented as regular modules in core::prelude and std::prelude. +New items can be added to the prelude, just beware that this can conflict with user's pre-existing +code. +Usually a migration lint should be used to migrate existing code to avoid the conflict. +For example, rust_2021_prelude_collisions is used to handle the collisions with the new traits +in 2021.

+

Customized language behavior

+

Usually it is not possible to make breaking changes to the standard library. +In some rare cases, the teams may decide that the behavior change is important enough to break this +rule. +The downside is that this requires special handling in the compiler to be able to distinguish when +the old and new signatures or behaviors should be used.

+

One example is the change in method resolution for into_iter() of arrays. +This was implemented with the #[rustc_skip_array_during_method_dispatch] attribute on the +IntoIterator trait which then tells the compiler to consider an alternate trait resolution choice +based on the edition.

+

Another example is the panic! macro changes. +This required defining multiple panic macros, and having the built-in panic macro implementation +determine the appropriate way to expand it. +This also included the non_fmt_panics migration lint to adjust old code to the new form, which +required the rustc_diagnostic_item attribute to detect the usage of the panic macro.

+

In general it is recommended to avoid these special cases except for very high value situations.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/highlight.css b/highlight.css new file mode 100644 index 000000000..ba57b82b2 --- /dev/null +++ b/highlight.css @@ -0,0 +1,82 @@ +/* + * An increased contrast highlighting scheme loosely based on the + * "Base16 Atelier Dune Light" theme by Bram de Haan + * (http://atelierbram.github.io/syntax-highlighting/atelier-schemes/dune) + * Original Base16 color scheme by Chris Kempson + * (https://github.com/chriskempson/base16) + */ + +/* Comment */ +.hljs-comment, +.hljs-quote { + color: #575757; +} + +/* Red */ +.hljs-variable, +.hljs-template-variable, +.hljs-attribute, +.hljs-tag, +.hljs-name, +.hljs-regexp, +.hljs-link, +.hljs-name, +.hljs-selector-id, +.hljs-selector-class { + color: #d70025; +} + +/* Orange */ +.hljs-number, +.hljs-meta, +.hljs-built_in, +.hljs-builtin-name, +.hljs-literal, +.hljs-type, +.hljs-params { + color: #b21e00; +} + +/* Green */ +.hljs-string, +.hljs-symbol, +.hljs-bullet { + color: #008200; +} + +/* Blue */ +.hljs-title, +.hljs-section { + color: #0030f2; +} + +/* Purple */ +.hljs-keyword, +.hljs-selector-tag { + color: #9d00ec; +} + +.hljs { + display: block; + overflow-x: auto; + background: #f6f7f6; + color: #000; +} + +.hljs-emphasis { + font-style: italic; +} + +.hljs-strong { + font-weight: bold; +} + +.hljs-addition { + color: #22863a; + background-color: #f0fff4; +} + +.hljs-deletion { + color: #b31d28; + background-color: #ffeef0; +} diff --git a/highlight.js b/highlight.js new file mode 100644 index 000000000..180385b70 --- /dev/null +++ b/highlight.js @@ -0,0 +1,6 @@ +/* + Highlight.js 10.1.1 (93fd0d73) + License: BSD-3-Clause + Copyright (c) 2006-2020, Ivan Sagalaev +*/ +var hljs=function(){"use strict";function e(n){Object.freeze(n);var t="function"==typeof n;return Object.getOwnPropertyNames(n).forEach((function(r){!Object.hasOwnProperty.call(n,r)||null===n[r]||"object"!=typeof n[r]&&"function"!=typeof n[r]||t&&("caller"===r||"callee"===r||"arguments"===r)||Object.isFrozen(n[r])||e(n[r])})),n}class n{constructor(e){void 0===e.data&&(e.data={}),this.data=e.data}ignoreMatch(){this.ignore=!0}}function t(e){return e.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function r(e,...n){var t={};for(const n in e)t[n]=e[n];return n.forEach((function(e){for(const n in e)t[n]=e[n]})),t}function a(e){return e.nodeName.toLowerCase()}var i=Object.freeze({__proto__:null,escapeHTML:t,inherit:r,nodeStream:function(e){var n=[];return function e(t,r){for(var i=t.firstChild;i;i=i.nextSibling)3===i.nodeType?r+=i.nodeValue.length:1===i.nodeType&&(n.push({event:"start",offset:r,node:i}),r=e(i,r),a(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:r,node:i}));return r}(e,0),n},mergeStreams:function(e,n,r){var i=0,s="",o=[];function l(){return e.length&&n.length?e[0].offset!==n[0].offset?e[0].offset"}function u(e){s+=""}function d(e){("start"===e.event?c:u)(e.node)}for(;e.length||n.length;){var g=l();if(s+=t(r.substring(i,g[0].offset)),i=g[0].offset,g===e){o.reverse().forEach(u);do{d(g.splice(0,1)[0]),g=l()}while(g===e&&g.length&&g[0].offset===i);o.reverse().forEach(c)}else"start"===g[0].event?o.push(g[0].node):o.pop(),d(g.splice(0,1)[0])}return s+t(r.substr(i))}});const s="",o=e=>!!e.kind;class l{constructor(e,n){this.buffer="",this.classPrefix=n.classPrefix,e.walk(this)}addText(e){this.buffer+=t(e)}openNode(e){if(!o(e))return;let n=e.kind;e.sublanguage||(n=`${this.classPrefix}${n}`),this.span(n)}closeNode(e){o(e)&&(this.buffer+=s)}value(){return this.buffer}span(e){this.buffer+=``}}class c{constructor(){this.rootNode={children:[]},this.stack=[this.rootNode]}get top(){return this.stack[this.stack.length-1]}get root(){return this.rootNode}add(e){this.top.children.push(e)}openNode(e){const n={kind:e,children:[]};this.add(n),this.stack.push(n)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(e){return this.constructor._walk(e,this.rootNode)}static _walk(e,n){return"string"==typeof n?e.addText(n):n.children&&(e.openNode(n),n.children.forEach(n=>this._walk(e,n)),e.closeNode(n)),e}static _collapse(e){"string"!=typeof e&&e.children&&(e.children.every(e=>"string"==typeof e)?e.children=[e.children.join("")]:e.children.forEach(e=>{c._collapse(e)}))}}class u extends c{constructor(e){super(),this.options=e}addKeyword(e,n){""!==e&&(this.openNode(n),this.addText(e),this.closeNode())}addText(e){""!==e&&this.add(e)}addSublanguage(e,n){const t=e.root;t.kind=n,t.sublanguage=!0,this.add(t)}toHTML(){return new l(this,this.options).value()}finalize(){return!0}}function d(e){return e?"string"==typeof e?e:e.source:null}const g="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",h={begin:"\\\\[\\s\\S]",relevance:0},f={className:"string",begin:"'",end:"'",illegal:"\\n",contains:[h]},p={className:"string",begin:'"',end:'"',illegal:"\\n",contains:[h]},b={begin:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},m=function(e,n,t={}){var a=r({className:"comment",begin:e,end:n,contains:[]},t);return a.contains.push(b),a.contains.push({className:"doctag",begin:"(?:TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):",relevance:0}),a},v=m("//","$"),x=m("/\\*","\\*/"),E=m("#","$");var _=Object.freeze({__proto__:null,IDENT_RE:"[a-zA-Z]\\w*",UNDERSCORE_IDENT_RE:"[a-zA-Z_]\\w*",NUMBER_RE:"\\b\\d+(\\.\\d+)?",C_NUMBER_RE:g,BINARY_NUMBER_RE:"\\b(0b[01]+)",RE_STARTERS_RE:"!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",SHEBANG:(e={})=>{const n=/^#![ ]*\//;return e.binary&&(e.begin=function(...e){return e.map(e=>d(e)).join("")}(n,/.*\b/,e.binary,/\b.*/)),r({className:"meta",begin:n,end:/$/,relevance:0,"on:begin":(e,n)=>{0!==e.index&&n.ignoreMatch()}},e)},BACKSLASH_ESCAPE:h,APOS_STRING_MODE:f,QUOTE_STRING_MODE:p,PHRASAL_WORDS_MODE:b,COMMENT:m,C_LINE_COMMENT_MODE:v,C_BLOCK_COMMENT_MODE:x,HASH_COMMENT_MODE:E,NUMBER_MODE:{className:"number",begin:"\\b\\d+(\\.\\d+)?",relevance:0},C_NUMBER_MODE:{className:"number",begin:g,relevance:0},BINARY_NUMBER_MODE:{className:"number",begin:"\\b(0b[01]+)",relevance:0},CSS_NUMBER_MODE:{className:"number",begin:"\\b\\d+(\\.\\d+)?(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",relevance:0},REGEXP_MODE:{begin:/(?=\/[^/\n]*\/)/,contains:[{className:"regexp",begin:/\//,end:/\/[gimuy]*/,illegal:/\n/,contains:[h,{begin:/\[/,end:/\]/,relevance:0,contains:[h]}]}]},TITLE_MODE:{className:"title",begin:"[a-zA-Z]\\w*",relevance:0},UNDERSCORE_TITLE_MODE:{className:"title",begin:"[a-zA-Z_]\\w*",relevance:0},METHOD_GUARD:{begin:"\\.\\s*[a-zA-Z_]\\w*",relevance:0},END_SAME_AS_BEGIN:function(e){return Object.assign(e,{"on:begin":(e,n)=>{n.data._beginMatch=e[1]},"on:end":(e,n)=>{n.data._beginMatch!==e[1]&&n.ignoreMatch()}})}}),N="of and for in not or if then".split(" ");function w(e,n){return n?+n:function(e){return N.includes(e.toLowerCase())}(e)?0:1}const R=t,y=r,{nodeStream:k,mergeStreams:O}=i,M=Symbol("nomatch");return function(t){var a=[],i={},s={},o=[],l=!0,c=/(^(<[^>]+>|\t|)+|\n)/gm,g="Could not find the language '{}', did you forget to load/include a language module?";const h={disableAutodetect:!0,name:"Plain text",contains:[]};var f={noHighlightRe:/^(no-?highlight)$/i,languageDetectRe:/\blang(?:uage)?-([\w-]+)\b/i,classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:null,__emitter:u};function p(e){return f.noHighlightRe.test(e)}function b(e,n,t,r){var a={code:n,language:e};S("before:highlight",a);var i=a.result?a.result:m(a.language,a.code,t,r);return i.code=a.code,S("after:highlight",i),i}function m(e,t,a,s){var o=t;function c(e,n){var t=E.case_insensitive?n[0].toLowerCase():n[0];return Object.prototype.hasOwnProperty.call(e.keywords,t)&&e.keywords[t]}function u(){null!=y.subLanguage?function(){if(""!==A){var e=null;if("string"==typeof y.subLanguage){if(!i[y.subLanguage])return void O.addText(A);e=m(y.subLanguage,A,!0,k[y.subLanguage]),k[y.subLanguage]=e.top}else e=v(A,y.subLanguage.length?y.subLanguage:null);y.relevance>0&&(I+=e.relevance),O.addSublanguage(e.emitter,e.language)}}():function(){if(!y.keywords)return void O.addText(A);let e=0;y.keywordPatternRe.lastIndex=0;let n=y.keywordPatternRe.exec(A),t="";for(;n;){t+=A.substring(e,n.index);const r=c(y,n);if(r){const[e,a]=r;O.addText(t),t="",I+=a,O.addKeyword(n[0],e)}else t+=n[0];e=y.keywordPatternRe.lastIndex,n=y.keywordPatternRe.exec(A)}t+=A.substr(e),O.addText(t)}(),A=""}function h(e){return e.className&&O.openNode(e.className),y=Object.create(e,{parent:{value:y}})}function p(e){return 0===y.matcher.regexIndex?(A+=e[0],1):(L=!0,0)}var b={};function x(t,r){var i=r&&r[0];if(A+=t,null==i)return u(),0;if("begin"===b.type&&"end"===r.type&&b.index===r.index&&""===i){if(A+=o.slice(r.index,r.index+1),!l){const n=Error("0 width match regex");throw n.languageName=e,n.badRule=b.rule,n}return 1}if(b=r,"begin"===r.type)return function(e){var t=e[0],r=e.rule;const a=new n(r),i=[r.__beforeBegin,r["on:begin"]];for(const n of i)if(n&&(n(e,a),a.ignore))return p(t);return r&&r.endSameAsBegin&&(r.endRe=RegExp(t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),"m")),r.skip?A+=t:(r.excludeBegin&&(A+=t),u(),r.returnBegin||r.excludeBegin||(A=t)),h(r),r.returnBegin?0:t.length}(r);if("illegal"===r.type&&!a){const e=Error('Illegal lexeme "'+i+'" for mode "'+(y.className||"")+'"');throw e.mode=y,e}if("end"===r.type){var s=function(e){var t=e[0],r=o.substr(e.index),a=function e(t,r,a){let i=function(e,n){var t=e&&e.exec(n);return t&&0===t.index}(t.endRe,a);if(i){if(t["on:end"]){const e=new n(t);t["on:end"](r,e),e.ignore&&(i=!1)}if(i){for(;t.endsParent&&t.parent;)t=t.parent;return t}}if(t.endsWithParent)return e(t.parent,r,a)}(y,e,r);if(!a)return M;var i=y;i.skip?A+=t:(i.returnEnd||i.excludeEnd||(A+=t),u(),i.excludeEnd&&(A=t));do{y.className&&O.closeNode(),y.skip||y.subLanguage||(I+=y.relevance),y=y.parent}while(y!==a.parent);return a.starts&&(a.endSameAsBegin&&(a.starts.endRe=a.endRe),h(a.starts)),i.returnEnd?0:t.length}(r);if(s!==M)return s}if("illegal"===r.type&&""===i)return 1;if(B>1e5&&B>3*r.index)throw Error("potential infinite loop, way more iterations than matches");return A+=i,i.length}var E=T(e);if(!E)throw console.error(g.replace("{}",e)),Error('Unknown language: "'+e+'"');var _=function(e){function n(n,t){return RegExp(d(n),"m"+(e.case_insensitive?"i":"")+(t?"g":""))}class t{constructor(){this.matchIndexes={},this.regexes=[],this.matchAt=1,this.position=0}addRule(e,n){n.position=this.position++,this.matchIndexes[this.matchAt]=n,this.regexes.push([n,e]),this.matchAt+=function(e){return RegExp(e.toString()+"|").exec("").length-1}(e)+1}compile(){0===this.regexes.length&&(this.exec=()=>null);const e=this.regexes.map(e=>e[1]);this.matcherRe=n(function(e,n="|"){for(var t=/\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./,r=0,a="",i=0;i0&&(a+=n),a+="(";o.length>0;){var l=t.exec(o);if(null==l){a+=o;break}a+=o.substring(0,l.index),o=o.substring(l.index+l[0].length),"\\"===l[0][0]&&l[1]?a+="\\"+(+l[1]+s):(a+=l[0],"("===l[0]&&r++)}a+=")"}return a}(e),!0),this.lastIndex=0}exec(e){this.matcherRe.lastIndex=this.lastIndex;const n=this.matcherRe.exec(e);if(!n)return null;const t=n.findIndex((e,n)=>n>0&&void 0!==e),r=this.matchIndexes[t];return n.splice(0,t),Object.assign(n,r)}}class a{constructor(){this.rules=[],this.multiRegexes=[],this.count=0,this.lastIndex=0,this.regexIndex=0}getMatcher(e){if(this.multiRegexes[e])return this.multiRegexes[e];const n=new t;return this.rules.slice(e).forEach(([e,t])=>n.addRule(e,t)),n.compile(),this.multiRegexes[e]=n,n}considerAll(){this.regexIndex=0}addRule(e,n){this.rules.push([e,n]),"begin"===n.type&&this.count++}exec(e){const n=this.getMatcher(this.regexIndex);n.lastIndex=this.lastIndex;const t=n.exec(e);return t&&(this.regexIndex+=t.position+1,this.regexIndex===this.count&&(this.regexIndex=0)),t}}function i(e,n){const t=e.input[e.index-1],r=e.input[e.index+e[0].length];"."!==t&&"."!==r||n.ignoreMatch()}if(e.contains&&e.contains.includes("self"))throw Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");return function t(s,o){const l=s;if(s.compiled)return l;s.compiled=!0,s.__beforeBegin=null,s.keywords=s.keywords||s.beginKeywords;let c=null;if("object"==typeof s.keywords&&(c=s.keywords.$pattern,delete s.keywords.$pattern),s.keywords&&(s.keywords=function(e,n){var t={};return"string"==typeof e?r("keyword",e):Object.keys(e).forEach((function(n){r(n,e[n])})),t;function r(e,r){n&&(r=r.toLowerCase()),r.split(" ").forEach((function(n){var r=n.split("|");t[r[0]]=[e,w(r[0],r[1])]}))}}(s.keywords,e.case_insensitive)),s.lexemes&&c)throw Error("ERR: Prefer `keywords.$pattern` to `mode.lexemes`, BOTH are not allowed. (see mode reference) ");return l.keywordPatternRe=n(s.lexemes||c||/\w+/,!0),o&&(s.beginKeywords&&(s.begin="\\b("+s.beginKeywords.split(" ").join("|")+")(?=\\b|\\s)",s.__beforeBegin=i),s.begin||(s.begin=/\B|\b/),l.beginRe=n(s.begin),s.endSameAsBegin&&(s.end=s.begin),s.end||s.endsWithParent||(s.end=/\B|\b/),s.end&&(l.endRe=n(s.end)),l.terminator_end=d(s.end)||"",s.endsWithParent&&o.terminator_end&&(l.terminator_end+=(s.end?"|":"")+o.terminator_end)),s.illegal&&(l.illegalRe=n(s.illegal)),void 0===s.relevance&&(s.relevance=1),s.contains||(s.contains=[]),s.contains=[].concat(...s.contains.map((function(e){return function(e){return e.variants&&!e.cached_variants&&(e.cached_variants=e.variants.map((function(n){return r(e,{variants:null},n)}))),e.cached_variants?e.cached_variants:function e(n){return!!n&&(n.endsWithParent||e(n.starts))}(e)?r(e,{starts:e.starts?r(e.starts):null}):Object.isFrozen(e)?r(e):e}("self"===e?s:e)}))),s.contains.forEach((function(e){t(e,l)})),s.starts&&t(s.starts,o),l.matcher=function(e){const n=new a;return e.contains.forEach(e=>n.addRule(e.begin,{rule:e,type:"begin"})),e.terminator_end&&n.addRule(e.terminator_end,{type:"end"}),e.illegal&&n.addRule(e.illegal,{type:"illegal"}),n}(l),l}(e)}(E),N="",y=s||_,k={},O=new f.__emitter(f);!function(){for(var e=[],n=y;n!==E;n=n.parent)n.className&&e.unshift(n.className);e.forEach(e=>O.openNode(e))}();var A="",I=0,S=0,B=0,L=!1;try{for(y.matcher.considerAll();;){B++,L?L=!1:(y.matcher.lastIndex=S,y.matcher.considerAll());const e=y.matcher.exec(o);if(!e)break;const n=x(o.substring(S,e.index),e);S=e.index+n}return x(o.substr(S)),O.closeAllNodes(),O.finalize(),N=O.toHTML(),{relevance:I,value:N,language:e,illegal:!1,emitter:O,top:y}}catch(n){if(n.message&&n.message.includes("Illegal"))return{illegal:!0,illegalBy:{msg:n.message,context:o.slice(S-100,S+100),mode:n.mode},sofar:N,relevance:0,value:R(o),emitter:O};if(l)return{illegal:!1,relevance:0,value:R(o),emitter:O,language:e,top:y,errorRaised:n};throw n}}function v(e,n){n=n||f.languages||Object.keys(i);var t=function(e){const n={relevance:0,emitter:new f.__emitter(f),value:R(e),illegal:!1,top:h};return n.emitter.addText(e),n}(e),r=t;return n.filter(T).filter(I).forEach((function(n){var a=m(n,e,!1);a.language=n,a.relevance>r.relevance&&(r=a),a.relevance>t.relevance&&(r=t,t=a)})),r.language&&(t.second_best=r),t}function x(e){return f.tabReplace||f.useBR?e.replace(c,e=>"\n"===e?f.useBR?"
":e:f.tabReplace?e.replace(/\t/g,f.tabReplace):e):e}function E(e){let n=null;const t=function(e){var n=e.className+" ";n+=e.parentNode?e.parentNode.className:"";const t=f.languageDetectRe.exec(n);if(t){var r=T(t[1]);return r||(console.warn(g.replace("{}",t[1])),console.warn("Falling back to no-highlight mode for this block.",e)),r?t[1]:"no-highlight"}return n.split(/\s+/).find(e=>p(e)||T(e))}(e);if(p(t))return;S("before:highlightBlock",{block:e,language:t}),f.useBR?(n=document.createElement("div")).innerHTML=e.innerHTML.replace(/\n/g,"").replace(//g,"\n"):n=e;const r=n.textContent,a=t?b(t,r,!0):v(r),i=k(n);if(i.length){const e=document.createElement("div");e.innerHTML=a.value,a.value=O(i,k(e),r)}a.value=x(a.value),S("after:highlightBlock",{block:e,result:a}),e.innerHTML=a.value,e.className=function(e,n,t){var r=n?s[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),e.includes(r)||a.push(r),a.join(" ").trim()}(e.className,t,a.language),e.result={language:a.language,re:a.relevance,relavance:a.relevance},a.second_best&&(e.second_best={language:a.second_best.language,re:a.second_best.relevance,relavance:a.second_best.relevance})}const N=()=>{if(!N.called){N.called=!0;var e=document.querySelectorAll("pre code");a.forEach.call(e,E)}};function T(e){return e=(e||"").toLowerCase(),i[e]||i[s[e]]}function A(e,{languageName:n}){"string"==typeof e&&(e=[e]),e.forEach(e=>{s[e]=n})}function I(e){var n=T(e);return n&&!n.disableAutodetect}function S(e,n){var t=e;o.forEach((function(e){e[t]&&e[t](n)}))}Object.assign(t,{highlight:b,highlightAuto:v,fixMarkup:x,highlightBlock:E,configure:function(e){f=y(f,e)},initHighlighting:N,initHighlightingOnLoad:function(){window.addEventListener("DOMContentLoaded",N,!1)},registerLanguage:function(e,n){var r=null;try{r=n(t)}catch(n){if(console.error("Language definition for '{}' could not be registered.".replace("{}",e)),!l)throw n;console.error(n),r=h}r.name||(r.name=e),i[e]=r,r.rawDefinition=n.bind(null,t),r.aliases&&A(r.aliases,{languageName:e})},listLanguages:function(){return Object.keys(i)},getLanguage:T,registerAliases:A,requireLanguage:function(e){var n=T(e);if(n)return n;throw Error("The '{}' language is required, but not loaded.".replace("{}",e))},autoDetection:I,inherit:y,addPlugin:function(e){o.push(e)}}),t.debugMode=function(){l=!1},t.safeMode=function(){l=!0},t.versionString="10.1.1";for(const n in _)"object"==typeof _[n]&&e(_[n]);return Object.assign(t,_),t}({})}();"object"==typeof exports&&"undefined"!=typeof module&&(module.exports=hljs);hljs.registerLanguage("php",function(){"use strict";return function(e){var r={begin:"\\$+[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*"},t={className:"meta",variants:[{begin:/<\?php/,relevance:10},{begin:/<\?[=]?/},{begin:/\?>/}]},a={className:"string",contains:[e.BACKSLASH_ESCAPE,t],variants:[{begin:'b"',end:'"'},{begin:"b'",end:"'"},e.inherit(e.APOS_STRING_MODE,{illegal:null}),e.inherit(e.QUOTE_STRING_MODE,{illegal:null})]},n={variants:[e.BINARY_NUMBER_MODE,e.C_NUMBER_MODE]},i={keyword:"__CLASS__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__ __NAMESPACE__ __TRAIT__ die echo exit include include_once print require require_once array abstract and as binary bool boolean break callable case catch class clone const continue declare default do double else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval extends final finally float for foreach from global goto if implements instanceof insteadof int integer interface isset iterable list new object or private protected public real return string switch throw trait try unset use var void while xor yield",literal:"false null true",built_in:"Error|0 AppendIterator ArgumentCountError ArithmeticError ArrayIterator ArrayObject AssertionError BadFunctionCallException BadMethodCallException CachingIterator CallbackFilterIterator CompileError Countable DirectoryIterator DivisionByZeroError DomainException EmptyIterator ErrorException Exception FilesystemIterator FilterIterator GlobIterator InfiniteIterator InvalidArgumentException IteratorIterator LengthException LimitIterator LogicException MultipleIterator NoRewindIterator OutOfBoundsException OutOfRangeException OuterIterator OverflowException ParentIterator ParseError RangeException RecursiveArrayIterator RecursiveCachingIterator RecursiveCallbackFilterIterator RecursiveDirectoryIterator RecursiveFilterIterator RecursiveIterator RecursiveIteratorIterator RecursiveRegexIterator RecursiveTreeIterator RegexIterator RuntimeException SeekableIterator SplDoublyLinkedList SplFileInfo SplFileObject SplFixedArray SplHeap SplMaxHeap SplMinHeap SplObjectStorage SplObserver SplObserver SplPriorityQueue SplQueue SplStack SplSubject SplSubject SplTempFileObject TypeError UnderflowException UnexpectedValueException ArrayAccess Closure Generator Iterator IteratorAggregate Serializable Throwable Traversable WeakReference Directory __PHP_Incomplete_Class parent php_user_filter self static stdClass"};return{aliases:["php","php3","php4","php5","php6","php7"],case_insensitive:!0,keywords:i,contains:[e.HASH_COMMENT_MODE,e.COMMENT("//","$",{contains:[t]}),e.COMMENT("/\\*","\\*/",{contains:[{className:"doctag",begin:"@[A-Za-z]+"}]}),e.COMMENT("__halt_compiler.+?;",!1,{endsWithParent:!0,keywords:"__halt_compiler"}),{className:"string",begin:/<<<['"]?\w+['"]?$/,end:/^\w+;?$/,contains:[e.BACKSLASH_ESCAPE,{className:"subst",variants:[{begin:/\$\w+/},{begin:/\{\$/,end:/\}/}]}]},t,{className:"keyword",begin:/\$this\b/},r,{begin:/(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/},{className:"function",beginKeywords:"fn function",end:/[;{]/,excludeEnd:!0,illegal:"[$%\\[]",contains:[e.UNDERSCORE_TITLE_MODE,{className:"params",begin:"\\(",end:"\\)",excludeBegin:!0,excludeEnd:!0,keywords:i,contains:["self",r,e.C_BLOCK_COMMENT_MODE,a,n]}]},{className:"class",beginKeywords:"class interface",end:"{",excludeEnd:!0,illegal:/[:\(\$"]/,contains:[{beginKeywords:"extends implements"},e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"namespace",end:";",illegal:/[\.']/,contains:[e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"use",end:";",contains:[e.UNDERSCORE_TITLE_MODE]},{begin:"=>"},a,n]}}}());hljs.registerLanguage("nginx",function(){"use strict";return function(e){var n={className:"variable",variants:[{begin:/\$\d+/},{begin:/\$\{/,end:/}/},{begin:"[\\$\\@]"+e.UNDERSCORE_IDENT_RE}]},a={endsWithParent:!0,keywords:{$pattern:"[a-z/_]+",literal:"on off yes no true false none blocked debug info notice warn error crit select break last permanent redirect kqueue rtsig epoll poll /dev/poll"},relevance:0,illegal:"=>",contains:[e.HASH_COMMENT_MODE,{className:"string",contains:[e.BACKSLASH_ESCAPE,n],variants:[{begin:/"/,end:/"/},{begin:/'/,end:/'/}]},{begin:"([a-z]+):/",end:"\\s",endsWithParent:!0,excludeEnd:!0,contains:[n]},{className:"regexp",contains:[e.BACKSLASH_ESCAPE,n],variants:[{begin:"\\s\\^",end:"\\s|{|;",returnEnd:!0},{begin:"~\\*?\\s+",end:"\\s|{|;",returnEnd:!0},{begin:"\\*(\\.[a-z\\-]+)+"},{begin:"([a-z\\-]+\\.)+\\*"}]},{className:"number",begin:"\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b"},{className:"number",begin:"\\b\\d+[kKmMgGdshdwy]*\\b",relevance:0},n]};return{name:"Nginx config",aliases:["nginxconf"],contains:[e.HASH_COMMENT_MODE,{begin:e.UNDERSCORE_IDENT_RE+"\\s+{",returnBegin:!0,end:"{",contains:[{className:"section",begin:e.UNDERSCORE_IDENT_RE}],relevance:0},{begin:e.UNDERSCORE_IDENT_RE+"\\s",end:";|{",returnBegin:!0,contains:[{className:"attribute",begin:e.UNDERSCORE_IDENT_RE,starts:a}],relevance:0}],illegal:"[^\\s\\}]"}}}());hljs.registerLanguage("csharp",function(){"use strict";return function(e){var n={keyword:"abstract as base bool break byte case catch char checked const continue decimal default delegate do double enum event explicit extern finally fixed float for foreach goto if implicit in int interface internal is lock long object operator out override params private protected public readonly ref sbyte sealed short sizeof stackalloc static string struct switch this try typeof uint ulong unchecked unsafe ushort using virtual void volatile while add alias ascending async await by descending dynamic equals from get global group into join let nameof on orderby partial remove select set value var when where yield",literal:"null false true"},i=e.inherit(e.TITLE_MODE,{begin:"[a-zA-Z](\\.?\\w)*"}),a={className:"number",variants:[{begin:"\\b(0b[01']+)"},{begin:"(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)(u|U|l|L|ul|UL|f|F|b|B)"},{begin:"(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)"}],relevance:0},s={className:"string",begin:'@"',end:'"',contains:[{begin:'""'}]},t=e.inherit(s,{illegal:/\n/}),l={className:"subst",begin:"{",end:"}",keywords:n},r=e.inherit(l,{illegal:/\n/}),c={className:"string",begin:/\$"/,end:'"',illegal:/\n/,contains:[{begin:"{{"},{begin:"}}"},e.BACKSLASH_ESCAPE,r]},o={className:"string",begin:/\$@"/,end:'"',contains:[{begin:"{{"},{begin:"}}"},{begin:'""'},l]},g=e.inherit(o,{illegal:/\n/,contains:[{begin:"{{"},{begin:"}}"},{begin:'""'},r]});l.contains=[o,c,s,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,a,e.C_BLOCK_COMMENT_MODE],r.contains=[g,c,t,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,a,e.inherit(e.C_BLOCK_COMMENT_MODE,{illegal:/\n/})];var d={variants:[o,c,s,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]},E={begin:"<",end:">",contains:[{beginKeywords:"in out"},i]},_=e.IDENT_RE+"(<"+e.IDENT_RE+"(\\s*,\\s*"+e.IDENT_RE+")*>)?(\\[\\])?",b={begin:"@"+e.IDENT_RE,relevance:0};return{name:"C#",aliases:["cs","c#"],keywords:n,illegal:/::/,contains:[e.COMMENT("///","$",{returnBegin:!0,contains:[{className:"doctag",variants:[{begin:"///",relevance:0},{begin:"\x3c!--|--\x3e"},{begin:""}]}]}),e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,{className:"meta",begin:"#",end:"$",keywords:{"meta-keyword":"if else elif endif define undef warning error line region endregion pragma checksum"}},d,a,{beginKeywords:"class interface",end:/[{;=]/,illegal:/[^\s:,]/,contains:[{beginKeywords:"where class"},i,E,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{beginKeywords:"namespace",end:/[{;=]/,illegal:/[^\s:]/,contains:[i,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{className:"meta",begin:"^\\s*\\[",excludeBegin:!0,end:"\\]",excludeEnd:!0,contains:[{className:"meta-string",begin:/"/,end:/"/}]},{beginKeywords:"new return throw await else",relevance:0},{className:"function",begin:"("+_+"\\s+)+"+e.IDENT_RE+"\\s*(\\<.+\\>)?\\s*\\(",returnBegin:!0,end:/\s*[{;=]/,excludeEnd:!0,keywords:n,contains:[{begin:e.IDENT_RE+"\\s*(\\<.+\\>)?\\s*\\(",returnBegin:!0,contains:[e.TITLE_MODE,E],relevance:0},{className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:n,relevance:0,contains:[d,a,e.C_BLOCK_COMMENT_MODE]},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},b]}}}());hljs.registerLanguage("perl",function(){"use strict";return function(e){var n={$pattern:/[\w.]+/,keyword:"getpwent getservent quotemeta msgrcv scalar kill dbmclose undef lc ma syswrite tr send umask sysopen shmwrite vec qx utime local oct semctl localtime readpipe do return format read sprintf dbmopen pop getpgrp not getpwnam rewinddir qq fileno qw endprotoent wait sethostent bless s|0 opendir continue each sleep endgrent shutdown dump chomp connect getsockname die socketpair close flock exists index shmget sub for endpwent redo lstat msgctl setpgrp abs exit select print ref gethostbyaddr unshift fcntl syscall goto getnetbyaddr join gmtime symlink semget splice x|0 getpeername recv log setsockopt cos last reverse gethostbyname getgrnam study formline endhostent times chop length gethostent getnetent pack getprotoent getservbyname rand mkdir pos chmod y|0 substr endnetent printf next open msgsnd readdir use unlink getsockopt getpriority rindex wantarray hex system getservbyport endservent int chr untie rmdir prototype tell listen fork shmread ucfirst setprotoent else sysseek link getgrgid shmctl waitpid unpack getnetbyname reset chdir grep split require caller lcfirst until warn while values shift telldir getpwuid my getprotobynumber delete and sort uc defined srand accept package seekdir getprotobyname semop our rename seek if q|0 chroot sysread setpwent no crypt getc chown sqrt write setnetent setpriority foreach tie sin msgget map stat getlogin unless elsif truncate exec keys glob tied closedir ioctl socket readlink eval xor readline binmode setservent eof ord bind alarm pipe atan2 getgrent exp time push setgrent gt lt or ne m|0 break given say state when"},t={className:"subst",begin:"[$@]\\{",end:"\\}",keywords:n},s={begin:"->{",end:"}"},r={variants:[{begin:/\$\d/},{begin:/[\$%@](\^\w\b|#\w+(::\w+)*|{\w+}|\w+(::\w*)*)/},{begin:/[\$%@][^\s\w{]/,relevance:0}]},i=[e.BACKSLASH_ESCAPE,t,r],a=[r,e.HASH_COMMENT_MODE,e.COMMENT("^\\=\\w","\\=cut",{endsWithParent:!0}),s,{className:"string",contains:i,variants:[{begin:"q[qwxr]?\\s*\\(",end:"\\)",relevance:5},{begin:"q[qwxr]?\\s*\\[",end:"\\]",relevance:5},{begin:"q[qwxr]?\\s*\\{",end:"\\}",relevance:5},{begin:"q[qwxr]?\\s*\\|",end:"\\|",relevance:5},{begin:"q[qwxr]?\\s*\\<",end:"\\>",relevance:5},{begin:"qw\\s+q",end:"q",relevance:5},{begin:"'",end:"'",contains:[e.BACKSLASH_ESCAPE]},{begin:'"',end:'"'},{begin:"`",end:"`",contains:[e.BACKSLASH_ESCAPE]},{begin:"{\\w+}",contains:[],relevance:0},{begin:"-?\\w+\\s*\\=\\>",contains:[],relevance:0}]},{className:"number",begin:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",relevance:0},{begin:"(\\/\\/|"+e.RE_STARTERS_RE+"|\\b(split|return|print|reverse|grep)\\b)\\s*",keywords:"split return print reverse grep",relevance:0,contains:[e.HASH_COMMENT_MODE,{className:"regexp",begin:"(s|tr|y)/(\\\\.|[^/])*/(\\\\.|[^/])*/[a-z]*",relevance:10},{className:"regexp",begin:"(m|qr)?/",end:"/[a-z]*",contains:[e.BACKSLASH_ESCAPE],relevance:0}]},{className:"function",beginKeywords:"sub",end:"(\\s*\\(.*?\\))?[;{]",excludeEnd:!0,relevance:5,contains:[e.TITLE_MODE]},{begin:"-\\w\\b",relevance:0},{begin:"^__DATA__$",end:"^__END__$",subLanguage:"mojolicious",contains:[{begin:"^@@.*",end:"$",className:"comment"}]}];return t.contains=a,s.contains=a,{name:"Perl",aliases:["pl","pm"],keywords:n,contains:a}}}());hljs.registerLanguage("swift",function(){"use strict";return function(e){var i={keyword:"#available #colorLiteral #column #else #elseif #endif #file #fileLiteral #function #if #imageLiteral #line #selector #sourceLocation _ __COLUMN__ __FILE__ __FUNCTION__ __LINE__ Any as as! as? associatedtype associativity break case catch class continue convenience default defer deinit didSet do dynamic dynamicType else enum extension fallthrough false fileprivate final for func get guard if import in indirect infix init inout internal is lazy left let mutating nil none nonmutating open operator optional override postfix precedence prefix private protocol Protocol public repeat required rethrows return right self Self set static struct subscript super switch throw throws true try try! try? Type typealias unowned var weak where while willSet",literal:"true false nil",built_in:"abs advance alignof alignofValue anyGenerator assert assertionFailure bridgeFromObjectiveC bridgeFromObjectiveCUnconditional bridgeToObjectiveC bridgeToObjectiveCUnconditional c compactMap contains count countElements countLeadingZeros debugPrint debugPrintln distance dropFirst dropLast dump encodeBitsAsWords enumerate equal fatalError filter find getBridgedObjectiveCType getVaList indices insertionSort isBridgedToObjectiveC isBridgedVerbatimToObjectiveC isUniquelyReferenced isUniquelyReferencedNonObjC join lazy lexicographicalCompare map max maxElement min minElement numericCast overlaps partition posix precondition preconditionFailure print println quickSort readLine reduce reflect reinterpretCast reverse roundUpToAlignment sizeof sizeofValue sort split startsWith stride strideof strideofValue swap toString transcode underestimateCount unsafeAddressOf unsafeBitCast unsafeDowncast unsafeUnwrap unsafeReflect withExtendedLifetime withObjectAtPlusZero withUnsafePointer withUnsafePointerToObject withUnsafeMutablePointer withUnsafeMutablePointers withUnsafePointer withUnsafePointers withVaList zip"},n=e.COMMENT("/\\*","\\*/",{contains:["self"]}),t={className:"subst",begin:/\\\(/,end:"\\)",keywords:i,contains:[]},a={className:"string",contains:[e.BACKSLASH_ESCAPE,t],variants:[{begin:/"""/,end:/"""/},{begin:/"/,end:/"/}]},r={className:"number",begin:"\\b([\\d_]+(\\.[\\deE_]+)?|0x[a-fA-F0-9_]+(\\.[a-fA-F0-9p_]+)?|0b[01_]+|0o[0-7_]+)\\b",relevance:0};return t.contains=[r],{name:"Swift",keywords:i,contains:[a,e.C_LINE_COMMENT_MODE,n,{className:"type",begin:"\\b[A-Z][\\wÀ-ʸ']*[!?]"},{className:"type",begin:"\\b[A-Z][\\wÀ-ʸ']*",relevance:0},r,{className:"function",beginKeywords:"func",end:"{",excludeEnd:!0,contains:[e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/}),{begin://},{className:"params",begin:/\(/,end:/\)/,endsParent:!0,keywords:i,contains:["self",r,a,e.C_BLOCK_COMMENT_MODE,{begin:":"}],illegal:/["']/}],illegal:/\[|%/},{className:"class",beginKeywords:"struct protocol class extension enum",keywords:i,end:"\\{",excludeEnd:!0,contains:[e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][\u00C0-\u02B80-9A-Za-z$_]*/})]},{className:"meta",begin:"(@discardableResult|@warn_unused_result|@exported|@lazy|@noescape|@NSCopying|@NSManaged|@objc|@objcMembers|@convention|@required|@noreturn|@IBAction|@IBDesignable|@IBInspectable|@IBOutlet|@infix|@prefix|@postfix|@autoclosure|@testable|@available|@nonobjc|@NSApplicationMain|@UIApplicationMain|@dynamicMemberLookup|@propertyWrapper)\\b"},{beginKeywords:"import",end:/$/,contains:[e.C_LINE_COMMENT_MODE,n]}]}}}());hljs.registerLanguage("makefile",function(){"use strict";return function(e){var i={className:"variable",variants:[{begin:"\\$\\("+e.UNDERSCORE_IDENT_RE+"\\)",contains:[e.BACKSLASH_ESCAPE]},{begin:/\$[@%`]+/}]}]}]};return{name:"HTML, XML",aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist","wsf","svg"],case_insensitive:!0,contains:[{className:"meta",begin:"",relevance:10,contains:[a,i,t,s,{begin:"\\[",end:"\\]",contains:[{className:"meta",begin:"",contains:[a,s,i,t]}]}]},e.COMMENT("\x3c!--","--\x3e",{relevance:10}),{begin:"<\\!\\[CDATA\\[",end:"\\]\\]>",relevance:10},n,{className:"meta",begin:/<\?xml/,end:/\?>/,relevance:10},{className:"tag",begin:")",end:">",keywords:{name:"style"},contains:[c],starts:{end:"",returnEnd:!0,subLanguage:["css","xml"]}},{className:"tag",begin:")",end:">",keywords:{name:"script"},contains:[c],starts:{end:"<\/script>",returnEnd:!0,subLanguage:["javascript","handlebars","xml"]}},{className:"tag",begin:"",contains:[{className:"name",begin:/[^\/><\s]+/,relevance:0},c]}]}}}());hljs.registerLanguage("bash",function(){"use strict";return function(e){const s={};Object.assign(s,{className:"variable",variants:[{begin:/\$[\w\d#@][\w\d_]*/},{begin:/\$\{/,end:/\}/,contains:[{begin:/:-/,contains:[s]}]}]});const t={className:"subst",begin:/\$\(/,end:/\)/,contains:[e.BACKSLASH_ESCAPE]},n={className:"string",begin:/"/,end:/"/,contains:[e.BACKSLASH_ESCAPE,s,t]};t.contains.push(n);const a={begin:/\$\(\(/,end:/\)\)/,contains:[{begin:/\d+#[0-9a-f]+/,className:"number"},e.NUMBER_MODE,s]},i=e.SHEBANG({binary:"(fish|bash|zsh|sh|csh|ksh|tcsh|dash|scsh)",relevance:10}),c={className:"function",begin:/\w[\w\d_]*\s*\(\s*\)\s*\{/,returnBegin:!0,contains:[e.inherit(e.TITLE_MODE,{begin:/\w[\w\d_]*/})],relevance:0};return{name:"Bash",aliases:["sh","zsh"],keywords:{$pattern:/\b-?[a-z\._]+\b/,keyword:"if then else elif fi for while in do done case esac function",literal:"true false",built_in:"break cd continue eval exec exit export getopts hash pwd readonly return shift test times trap umask unset alias bind builtin caller command declare echo enable help let local logout mapfile printf read readarray source type typeset ulimit unalias set shopt autoload bg bindkey bye cap chdir clone comparguments compcall compctl compdescribe compfiles compgroups compquote comptags comptry compvalues dirs disable disown echotc echoti emulate fc fg float functions getcap getln history integer jobs kill limit log noglob popd print pushd pushln rehash sched setcap setopt stat suspend ttyctl unfunction unhash unlimit unsetopt vared wait whence where which zcompile zformat zftp zle zmodload zparseopts zprof zpty zregexparse zsocket zstyle ztcp",_:"-ne -eq -lt -gt -f -d -e -s -l -a"},contains:[i,e.SHEBANG(),c,a,e.HASH_COMMENT_MODE,n,{className:"",begin:/\\"/},{className:"string",begin:/'/,end:/'/},s]}}}());hljs.registerLanguage("c-like",function(){"use strict";return function(e){function t(e){return"(?:"+e+")?"}var n="(decltype\\(auto\\)|"+t("[a-zA-Z_]\\w*::")+"[a-zA-Z_]\\w*"+t("<.*?>")+")",r={className:"keyword",begin:"\\b[a-z\\d_]*_t\\b"},a={className:"string",variants:[{begin:'(u8?|U|L)?"',end:'"',illegal:"\\n",contains:[e.BACKSLASH_ESCAPE]},{begin:"(u8?|U|L)?'(\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)|.)",end:"'",illegal:"."},e.END_SAME_AS_BEGIN({begin:/(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,end:/\)([^()\\ ]{0,16})"/})]},i={className:"number",variants:[{begin:"\\b(0b[01']+)"},{begin:"(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)(u|U|l|L|ul|UL|f|F|b|B)"},{begin:"(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)"}],relevance:0},s={className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{"meta-keyword":"if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include"},contains:[{begin:/\\\n/,relevance:0},e.inherit(a,{className:"meta-string"}),{className:"meta-string",begin:/<.*?>/,end:/$/,illegal:"\\n"},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},o={className:"title",begin:t("[a-zA-Z_]\\w*::")+e.IDENT_RE,relevance:0},c=t("[a-zA-Z_]\\w*::")+e.IDENT_RE+"\\s*\\(",l={keyword:"int float while private char char8_t char16_t char32_t catch import module export virtual operator sizeof dynamic_cast|10 typedef const_cast|10 const for static_cast|10 union namespace unsigned long volatile static protected bool template mutable if public friend do goto auto void enum else break extern using asm case typeid wchar_t short reinterpret_cast|10 default double register explicit signed typename try this switch continue inline delete alignas alignof constexpr consteval constinit decltype concept co_await co_return co_yield requires noexcept static_assert thread_local restrict final override atomic_bool atomic_char atomic_schar atomic_uchar atomic_short atomic_ushort atomic_int atomic_uint atomic_long atomic_ulong atomic_llong atomic_ullong new throw return and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq",built_in:"std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr _Bool complex _Complex imaginary _Imaginary",literal:"true false nullptr NULL"},d=[r,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,i,a],_={variants:[{begin:/=/,end:/;/},{begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],keywords:l,contains:d.concat([{begin:/\(/,end:/\)/,keywords:l,contains:d.concat(["self"]),relevance:0}]),relevance:0},u={className:"function",begin:"("+n+"[\\*&\\s]+)+"+c,returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:l,illegal:/[^\w\s\*&:<>]/,contains:[{begin:"decltype\\(auto\\)",keywords:l,relevance:0},{begin:c,returnBegin:!0,contains:[o],relevance:0},{className:"params",begin:/\(/,end:/\)/,keywords:l,relevance:0,contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,i,r,{begin:/\(/,end:/\)/,keywords:l,relevance:0,contains:["self",e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,i,r]}]},r,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s]};return{aliases:["c","cc","h","c++","h++","hpp","hh","hxx","cxx"],keywords:l,disableAutodetect:!0,illegal:"",keywords:l,contains:["self",r]},{begin:e.IDENT_RE+"::",keywords:l},{className:"class",beginKeywords:"class struct",end:/[{;:]/,contains:[{begin://,contains:["self"]},e.TITLE_MODE]}]),exports:{preprocessor:s,strings:a,keywords:l}}}}());hljs.registerLanguage("coffeescript",function(){"use strict";const e=["as","in","of","if","for","while","finally","var","new","function","do","return","void","else","break","catch","instanceof","with","throw","case","default","try","switch","continue","typeof","delete","let","yield","const","class","debugger","async","await","static","import","from","export","extends"],n=["true","false","null","undefined","NaN","Infinity"],a=[].concat(["setInterval","setTimeout","clearInterval","clearTimeout","require","exports","eval","isFinite","isNaN","parseFloat","parseInt","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape"],["arguments","this","super","console","window","document","localStorage","module","global"],["Intl","DataView","Number","Math","Date","String","RegExp","Object","Function","Boolean","Error","Symbol","Set","Map","WeakSet","WeakMap","Proxy","Reflect","JSON","Promise","Float64Array","Int16Array","Int32Array","Int8Array","Uint16Array","Uint32Array","Float32Array","Array","Uint8Array","Uint8ClampedArray","ArrayBuffer"],["EvalError","InternalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError"]);return function(r){var t={keyword:e.concat(["then","unless","until","loop","by","when","and","or","is","isnt","not"]).filter((e=>n=>!e.includes(n))(["var","const","let","function","static"])).join(" "),literal:n.concat(["yes","no","on","off"]).join(" "),built_in:a.concat(["npm","print"]).join(" ")},i="[A-Za-z$_][0-9A-Za-z$_]*",s={className:"subst",begin:/#\{/,end:/}/,keywords:t},o=[r.BINARY_NUMBER_MODE,r.inherit(r.C_NUMBER_MODE,{starts:{end:"(\\s*/)?",relevance:0}}),{className:"string",variants:[{begin:/'''/,end:/'''/,contains:[r.BACKSLASH_ESCAPE]},{begin:/'/,end:/'/,contains:[r.BACKSLASH_ESCAPE]},{begin:/"""/,end:/"""/,contains:[r.BACKSLASH_ESCAPE,s]},{begin:/"/,end:/"/,contains:[r.BACKSLASH_ESCAPE,s]}]},{className:"regexp",variants:[{begin:"///",end:"///",contains:[s,r.HASH_COMMENT_MODE]},{begin:"//[gim]{0,3}(?=\\W)",relevance:0},{begin:/\/(?![ *]).*?(?![\\]).\/[gim]{0,3}(?=\W)/}]},{begin:"@"+i},{subLanguage:"javascript",excludeBegin:!0,excludeEnd:!0,variants:[{begin:"```",end:"```"},{begin:"`",end:"`"}]}];s.contains=o;var c=r.inherit(r.TITLE_MODE,{begin:i}),l={className:"params",begin:"\\([^\\(]",returnBegin:!0,contains:[{begin:/\(/,end:/\)/,keywords:t,contains:["self"].concat(o)}]};return{name:"CoffeeScript",aliases:["coffee","cson","iced"],keywords:t,illegal:/\/\*/,contains:o.concat([r.COMMENT("###","###"),r.HASH_COMMENT_MODE,{className:"function",begin:"^\\s*"+i+"\\s*=\\s*(\\(.*\\))?\\s*\\B[-=]>",end:"[-=]>",returnBegin:!0,contains:[c,l]},{begin:/[:\(,=]\s*/,relevance:0,contains:[{className:"function",begin:"(\\(.*\\))?\\s*\\B[-=]>",end:"[-=]>",returnBegin:!0,contains:[l]}]},{className:"class",beginKeywords:"class",end:"$",illegal:/[:="\[\]]/,contains:[{beginKeywords:"extends",endsWithParent:!0,illegal:/[:="\[\]]/,contains:[c]},c]},{begin:i+":",end:":",returnBegin:!0,returnEnd:!0,relevance:0}])}}}());hljs.registerLanguage("ruby",function(){"use strict";return function(e){var n="[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?",a={keyword:"and then defined module in return redo if BEGIN retry end for self when next until do begin unless END rescue else break undef not super class case require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor",literal:"true false nil"},s={className:"doctag",begin:"@[A-Za-z]+"},i={begin:"#<",end:">"},r=[e.COMMENT("#","$",{contains:[s]}),e.COMMENT("^\\=begin","^\\=end",{contains:[s],relevance:10}),e.COMMENT("^__END__","\\n$")],c={className:"subst",begin:"#\\{",end:"}",keywords:a},t={className:"string",contains:[e.BACKSLASH_ESCAPE,c],variants:[{begin:/'/,end:/'/},{begin:/"/,end:/"/},{begin:/`/,end:/`/},{begin:"%[qQwWx]?\\(",end:"\\)"},{begin:"%[qQwWx]?\\[",end:"\\]"},{begin:"%[qQwWx]?{",end:"}"},{begin:"%[qQwWx]?<",end:">"},{begin:"%[qQwWx]?/",end:"/"},{begin:"%[qQwWx]?%",end:"%"},{begin:"%[qQwWx]?-",end:"-"},{begin:"%[qQwWx]?\\|",end:"\\|"},{begin:/\B\?(\\\d{1,3}|\\x[A-Fa-f0-9]{1,2}|\\u[A-Fa-f0-9]{4}|\\?\S)\b/},{begin:/<<[-~]?'?(\w+)(?:.|\n)*?\n\s*\1\b/,returnBegin:!0,contains:[{begin:/<<[-~]?'?/},e.END_SAME_AS_BEGIN({begin:/(\w+)/,end:/(\w+)/,contains:[e.BACKSLASH_ESCAPE,c]})]}]},b={className:"params",begin:"\\(",end:"\\)",endsParent:!0,keywords:a},d=[t,i,{className:"class",beginKeywords:"class module",end:"$|;",illegal:/=/,contains:[e.inherit(e.TITLE_MODE,{begin:"[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?"}),{begin:"<\\s*",contains:[{begin:"("+e.IDENT_RE+"::)?"+e.IDENT_RE}]}].concat(r)},{className:"function",beginKeywords:"def",end:"$|;",contains:[e.inherit(e.TITLE_MODE,{begin:n}),b].concat(r)},{begin:e.IDENT_RE+"::"},{className:"symbol",begin:e.UNDERSCORE_IDENT_RE+"(\\!|\\?)?:",relevance:0},{className:"symbol",begin:":(?!\\s)",contains:[t,{begin:n}],relevance:0},{className:"number",begin:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",relevance:0},{begin:"(\\$\\W)|((\\$|\\@\\@?)(\\w+))"},{className:"params",begin:/\|/,end:/\|/,keywords:a},{begin:"("+e.RE_STARTERS_RE+"|unless)\\s*",keywords:"unless",contains:[i,{className:"regexp",contains:[e.BACKSLASH_ESCAPE,c],illegal:/\n/,variants:[{begin:"/",end:"/[a-z]*"},{begin:"%r{",end:"}[a-z]*"},{begin:"%r\\(",end:"\\)[a-z]*"},{begin:"%r!",end:"![a-z]*"},{begin:"%r\\[",end:"\\][a-z]*"}]}].concat(r),relevance:0}].concat(r);c.contains=d,b.contains=d;var g=[{begin:/^\s*=>/,starts:{end:"$",contains:d}},{className:"meta",begin:"^([>?]>|[\\w#]+\\(\\w+\\):\\d+:\\d+>|(\\w+-)?\\d+\\.\\d+\\.\\d(p\\d+)?[^>]+>)",starts:{end:"$",contains:d}}];return{name:"Ruby",aliases:["rb","gemspec","podspec","thor","irb"],keywords:a,illegal:/\/\*/,contains:r.concat(g).concat(d)}}}());hljs.registerLanguage("yaml",function(){"use strict";return function(e){var n="true false yes no null",a="[\\w#;/?:@&=+$,.~*\\'()[\\]]+",s={className:"string",relevance:0,variants:[{begin:/'/,end:/'/},{begin:/"/,end:/"/},{begin:/\S+/}],contains:[e.BACKSLASH_ESCAPE,{className:"template-variable",variants:[{begin:"{{",end:"}}"},{begin:"%{",end:"}"}]}]},i=e.inherit(s,{variants:[{begin:/'/,end:/'/},{begin:/"/,end:/"/},{begin:/[^\s,{}[\]]+/}]}),l={end:",",endsWithParent:!0,excludeEnd:!0,contains:[],keywords:n,relevance:0},t={begin:"{",end:"}",contains:[l],illegal:"\\n",relevance:0},g={begin:"\\[",end:"\\]",contains:[l],illegal:"\\n",relevance:0},b=[{className:"attr",variants:[{begin:"\\w[\\w :\\/.-]*:(?=[ \t]|$)"},{begin:'"\\w[\\w :\\/.-]*":(?=[ \t]|$)'},{begin:"'\\w[\\w :\\/.-]*':(?=[ \t]|$)"}]},{className:"meta",begin:"^---s*$",relevance:10},{className:"string",begin:"[\\|>]([0-9]?[+-])?[ ]*\\n( *)[\\S ]+\\n(\\2[\\S ]+\\n?)*"},{begin:"<%[%=-]?",end:"[%-]?%>",subLanguage:"ruby",excludeBegin:!0,excludeEnd:!0,relevance:0},{className:"type",begin:"!\\w+!"+a},{className:"type",begin:"!<"+a+">"},{className:"type",begin:"!"+a},{className:"type",begin:"!!"+a},{className:"meta",begin:"&"+e.UNDERSCORE_IDENT_RE+"$"},{className:"meta",begin:"\\*"+e.UNDERSCORE_IDENT_RE+"$"},{className:"bullet",begin:"\\-(?=[ ]|$)",relevance:0},e.HASH_COMMENT_MODE,{beginKeywords:n,keywords:{literal:n}},{className:"number",begin:"\\b[0-9]{4}(-[0-9][0-9]){0,2}([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?(\\.[0-9]*)?([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?\\b"},{className:"number",begin:e.C_NUMBER_RE+"\\b"},t,g,s],c=[...b];return c.pop(),c.push(i),l.contains=c,{name:"YAML",case_insensitive:!0,aliases:["yml","YAML"],contains:b}}}());hljs.registerLanguage("d",function(){"use strict";return function(e){var a={$pattern:e.UNDERSCORE_IDENT_RE,keyword:"abstract alias align asm assert auto body break byte case cast catch class const continue debug default delete deprecated do else enum export extern final finally for foreach foreach_reverse|10 goto if immutable import in inout int interface invariant is lazy macro mixin module new nothrow out override package pragma private protected public pure ref return scope shared static struct super switch synchronized template this throw try typedef typeid typeof union unittest version void volatile while with __FILE__ __LINE__ __gshared|10 __thread __traits __DATE__ __EOF__ __TIME__ __TIMESTAMP__ __VENDOR__ __VERSION__",built_in:"bool cdouble cent cfloat char creal dchar delegate double dstring float function idouble ifloat ireal long real short string ubyte ucent uint ulong ushort wchar wstring",literal:"false null true"},d="((0|[1-9][\\d_]*)|0[bB][01_]+|0[xX]([\\da-fA-F][\\da-fA-F_]*|_[\\da-fA-F][\\da-fA-F_]*))",n="\\\\(['\"\\?\\\\abfnrtv]|u[\\dA-Fa-f]{4}|[0-7]{1,3}|x[\\dA-Fa-f]{2}|U[\\dA-Fa-f]{8})|&[a-zA-Z\\d]{2,};",t={className:"number",begin:"\\b"+d+"(L|u|U|Lu|LU|uL|UL)?",relevance:0},_={className:"number",begin:"\\b(((0[xX](([\\da-fA-F][\\da-fA-F_]*|_[\\da-fA-F][\\da-fA-F_]*)\\.([\\da-fA-F][\\da-fA-F_]*|_[\\da-fA-F][\\da-fA-F_]*)|\\.?([\\da-fA-F][\\da-fA-F_]*|_[\\da-fA-F][\\da-fA-F_]*))[pP][+-]?(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d))|((0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d)(\\.\\d*|([eE][+-]?(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d)))|\\d+\\.(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d)(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d)|\\.(0|[1-9][\\d_]*)([eE][+-]?(0|[1-9][\\d_]*|\\d[\\d_]*|[\\d_]+?\\d))?))([fF]|L|i|[fF]i|Li)?|"+d+"(i|[fF]i|Li))",relevance:0},r={className:"string",begin:"'("+n+"|.)",end:"'",illegal:"."},i={className:"string",begin:'"',contains:[{begin:n,relevance:0}],end:'"[cwd]?'},s=e.COMMENT("\\/\\+","\\+\\/",{contains:["self"],relevance:10});return{name:"D",keywords:a,contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s,{className:"string",begin:'x"[\\da-fA-F\\s\\n\\r]*"[cwd]?',relevance:10},i,{className:"string",begin:'[rq]"',end:'"[cwd]?',relevance:5},{className:"string",begin:"`",end:"`[cwd]?"},{className:"string",begin:'q"\\{',end:'\\}"'},_,t,r,{className:"meta",begin:"^#!",end:"$",relevance:5},{className:"meta",begin:"#(line)",end:"$",relevance:5},{className:"keyword",begin:"@[a-zA-Z_][a-zA-Z_\\d]*"}]}}}());hljs.registerLanguage("properties",function(){"use strict";return function(e){var n="[ \\t\\f]*",t="("+n+"[:=]"+n+"|[ \\t\\f]+)",a="([^\\\\:= \\t\\f\\n]|\\\\.)+",s={end:t,relevance:0,starts:{className:"string",end:/$/,relevance:0,contains:[{begin:"\\\\\\n"}]}};return{name:".properties",case_insensitive:!0,illegal:/\S/,contains:[e.COMMENT("^\\s*[!#]","$"),{begin:"([^\\\\\\W:= \\t\\f\\n]|\\\\.)+"+t,returnBegin:!0,contains:[{className:"attr",begin:"([^\\\\\\W:= \\t\\f\\n]|\\\\.)+",endsParent:!0,relevance:0}],starts:s},{begin:a+t,returnBegin:!0,relevance:0,contains:[{className:"meta",begin:a,endsParent:!0,relevance:0}],starts:s},{className:"attr",relevance:0,begin:a+n+"$"}]}}}());hljs.registerLanguage("http",function(){"use strict";return function(e){var n="HTTP/[0-9\\.]+";return{name:"HTTP",aliases:["https"],illegal:"\\S",contains:[{begin:"^"+n,end:"$",contains:[{className:"number",begin:"\\b\\d{3}\\b"}]},{begin:"^[A-Z]+ (.*?) "+n+"$",returnBegin:!0,end:"$",contains:[{className:"string",begin:" ",end:" ",excludeBegin:!0,excludeEnd:!0},{begin:n},{className:"keyword",begin:"[A-Z]+"}]},{className:"attribute",begin:"^\\w",end:": ",excludeEnd:!0,illegal:"\\n|\\s|=",starts:{end:"$",relevance:0}},{begin:"\\n\\n",starts:{subLanguage:[],endsWithParent:!0}}]}}}());hljs.registerLanguage("haskell",function(){"use strict";return function(e){var n={variants:[e.COMMENT("--","$"),e.COMMENT("{-","-}",{contains:["self"]})]},i={className:"meta",begin:"{-#",end:"#-}"},a={className:"meta",begin:"^#",end:"$"},s={className:"type",begin:"\\b[A-Z][\\w']*",relevance:0},l={begin:"\\(",end:"\\)",illegal:'"',contains:[i,a,{className:"type",begin:"\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?"},e.inherit(e.TITLE_MODE,{begin:"[_a-z][\\w']*"}),n]};return{name:"Haskell",aliases:["hs"],keywords:"let in if then else case of where do module import hiding qualified type data newtype deriving class instance as default infix infixl infixr foreign export ccall stdcall cplusplus jvm dotnet safe unsafe family forall mdo proc rec",contains:[{beginKeywords:"module",end:"where",keywords:"module where",contains:[l,n],illegal:"\\W\\.|;"},{begin:"\\bimport\\b",end:"$",keywords:"import qualified as hiding",contains:[l,n],illegal:"\\W\\.|;"},{className:"class",begin:"^(\\s*)?(class|instance)\\b",end:"where",keywords:"class family instance where",contains:[s,l,n]},{className:"class",begin:"\\b(data|(new)?type)\\b",end:"$",keywords:"data family type newtype deriving",contains:[i,s,l,{begin:"{",end:"}",contains:l.contains},n]},{beginKeywords:"default",end:"$",contains:[s,l,n]},{beginKeywords:"infix infixl infixr",end:"$",contains:[e.C_NUMBER_MODE,n]},{begin:"\\bforeign\\b",end:"$",keywords:"foreign import export ccall stdcall cplusplus jvm dotnet safe unsafe",contains:[s,e.QUOTE_STRING_MODE,n]},{className:"meta",begin:"#!\\/usr\\/bin\\/env runhaskell",end:"$"},i,a,e.QUOTE_STRING_MODE,e.C_NUMBER_MODE,s,e.inherit(e.TITLE_MODE,{begin:"^[_a-z][\\w']*"}),n,{begin:"->|<-"}]}}}());hljs.registerLanguage("handlebars",function(){"use strict";function e(...e){return e.map(e=>(function(e){return e?"string"==typeof e?e:e.source:null})(e)).join("")}return function(n){const a={"builtin-name":"action bindattr collection component concat debugger each each-in get hash if in input link-to loc log lookup mut outlet partial query-params render template textarea unbound unless view with yield"},t=/\[.*?\]/,s=/[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+/,i=e("(",/'.*?'/,"|",/".*?"/,"|",t,"|",s,"|",/\.|\//,")+"),r=e("(",t,"|",s,")(?==)"),l={begin:i,lexemes:/[\w.\/]+/},c=n.inherit(l,{keywords:{literal:"true false undefined null"}}),o={begin:/\(/,end:/\)/},m={className:"attr",begin:r,relevance:0,starts:{begin:/=/,end:/=/,starts:{contains:[n.NUMBER_MODE,n.QUOTE_STRING_MODE,n.APOS_STRING_MODE,c,o]}}},d={contains:[n.NUMBER_MODE,n.QUOTE_STRING_MODE,n.APOS_STRING_MODE,{begin:/as\s+\|/,keywords:{keyword:"as"},end:/\|/,contains:[{begin:/\w+/}]},m,c,o],returnEnd:!0},g=n.inherit(l,{className:"name",keywords:a,starts:n.inherit(d,{end:/\)/})});o.contains=[g];const u=n.inherit(l,{keywords:a,className:"name",starts:n.inherit(d,{end:/}}/})}),b=n.inherit(l,{keywords:a,className:"name"}),h=n.inherit(l,{className:"name",keywords:a,starts:n.inherit(d,{end:/}}/})});return{name:"Handlebars",aliases:["hbs","html.hbs","html.handlebars","htmlbars"],case_insensitive:!0,subLanguage:"xml",contains:[{begin:/\\\{\{/,skip:!0},{begin:/\\\\(?=\{\{)/,skip:!0},n.COMMENT(/\{\{!--/,/--\}\}/),n.COMMENT(/\{\{!/,/\}\}/),{className:"template-tag",begin:/\{\{\{\{(?!\/)/,end:/\}\}\}\}/,contains:[u],starts:{end:/\{\{\{\{\//,returnEnd:!0,subLanguage:"xml"}},{className:"template-tag",begin:/\{\{\{\{\//,end:/\}\}\}\}/,contains:[b]},{className:"template-tag",begin:/\{\{#/,end:/\}\}/,contains:[u]},{className:"template-tag",begin:/\{\{(?=else\}\})/,end:/\}\}/,keywords:"else"},{className:"template-tag",begin:/\{\{\//,end:/\}\}/,contains:[b]},{className:"template-variable",begin:/\{\{\{/,end:/\}\}\}/,contains:[h]},{className:"template-variable",begin:/\{\{/,end:/\}\}/,contains:[h]}]}}}());hljs.registerLanguage("rust",function(){"use strict";return function(e){var n="([ui](8|16|32|64|128|size)|f(32|64))?",t="drop i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize f32 f64 str char bool Box Option Result String Vec Copy Send Sized Sync Drop Fn FnMut FnOnce ToOwned Clone Debug PartialEq PartialOrd Eq Ord AsRef AsMut Into From Default Iterator Extend IntoIterator DoubleEndedIterator ExactSizeIterator SliceConcatExt ToString assert! assert_eq! bitflags! bytes! cfg! col! concat! concat_idents! debug_assert! debug_assert_eq! env! panic! file! format! format_args! include_bin! include_str! line! local_data_key! module_path! option_env! print! println! select! stringify! try! unimplemented! unreachable! vec! write! writeln! macro_rules! assert_ne! debug_assert_ne!";return{name:"Rust",aliases:["rs"],keywords:{$pattern:e.IDENT_RE+"!?",keyword:"abstract as async await become box break const continue crate do dyn else enum extern false final fn for if impl in let loop macro match mod move mut override priv pub ref return self Self static struct super trait true try type typeof unsafe unsized use virtual where while yield",literal:"true false Some None Ok Err",built_in:t},illegal:""}]}}}());hljs.registerLanguage("cpp",function(){"use strict";return function(e){var t=e.getLanguage("c-like").rawDefinition();return t.disableAutodetect=!1,t.name="C++",t.aliases=["cc","c++","h++","hpp","hh","hxx","cxx"],t}}());hljs.registerLanguage("ini",function(){"use strict";function e(e){return e?"string"==typeof e?e:e.source:null}function n(...n){return n.map(n=>e(n)).join("")}return function(a){var s={className:"number",relevance:0,variants:[{begin:/([\+\-]+)?[\d]+_[\d_]+/},{begin:a.NUMBER_RE}]},i=a.COMMENT();i.variants=[{begin:/;/,end:/$/},{begin:/#/,end:/$/}];var t={className:"variable",variants:[{begin:/\$[\w\d"][\w\d_]*/},{begin:/\$\{(.*?)}/}]},r={className:"literal",begin:/\bon|off|true|false|yes|no\b/},l={className:"string",contains:[a.BACKSLASH_ESCAPE],variants:[{begin:"'''",end:"'''",relevance:10},{begin:'"""',end:'"""',relevance:10},{begin:'"',end:'"'},{begin:"'",end:"'"}]},c={begin:/\[/,end:/\]/,contains:[i,r,t,l,s,"self"],relevance:0},g="("+[/[A-Za-z0-9_-]+/,/"(\\"|[^"])*"/,/'[^']*'/].map(n=>e(n)).join("|")+")";return{name:"TOML, also INI",aliases:["toml"],case_insensitive:!0,illegal:/\S/,contains:[i,{className:"section",begin:/\[+/,end:/\]+/},{begin:n(g,"(\\s*\\.\\s*",g,")*",n("(?=",/\s*=\s*[^#\s]/,")")),className:"attr",starts:{end:/$/,contains:[i,c,r,t,l,s]}}]}}}());hljs.registerLanguage("objectivec",function(){"use strict";return function(e){var n=/[a-zA-Z@][a-zA-Z0-9_]*/,_={$pattern:n,keyword:"@interface @class @protocol @implementation"};return{name:"Objective-C",aliases:["mm","objc","obj-c"],keywords:{$pattern:n,keyword:"int float while char export sizeof typedef const struct for union unsigned long volatile static bool mutable if do return goto void enum else break extern asm case short default double register explicit signed typename this switch continue wchar_t inline readonly assign readwrite self @synchronized id typeof nonatomic super unichar IBOutlet IBAction strong weak copy in out inout bycopy byref oneway __strong __weak __block __autoreleasing @private @protected @public @try @property @end @throw @catch @finally @autoreleasepool @synthesize @dynamic @selector @optional @required @encode @package @import @defs @compatibility_alias __bridge __bridge_transfer __bridge_retained __bridge_retain __covariant __contravariant __kindof _Nonnull _Nullable _Null_unspecified __FUNCTION__ __PRETTY_FUNCTION__ __attribute__ getter setter retain unsafe_unretained nonnull nullable null_unspecified null_resettable class instancetype NS_DESIGNATED_INITIALIZER NS_UNAVAILABLE NS_REQUIRES_SUPER NS_RETURNS_INNER_POINTER NS_INLINE NS_AVAILABLE NS_DEPRECATED NS_ENUM NS_OPTIONS NS_SWIFT_UNAVAILABLE NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END NS_REFINED_FOR_SWIFT NS_SWIFT_NAME NS_SWIFT_NOTHROW NS_DURING NS_HANDLER NS_ENDHANDLER NS_VALUERETURN NS_VOIDRETURN",literal:"false true FALSE TRUE nil YES NO NULL",built_in:"BOOL dispatch_once_t dispatch_queue_t dispatch_sync dispatch_async dispatch_once"},illegal:"/,end:/$/,illegal:"\\n"},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{className:"class",begin:"("+_.keyword.split(" ").join("|")+")\\b",end:"({|$)",excludeEnd:!0,keywords:_,contains:[e.UNDERSCORE_TITLE_MODE]},{begin:"\\."+e.UNDERSCORE_IDENT_RE,relevance:0}]}}}());hljs.registerLanguage("apache",function(){"use strict";return function(e){var n={className:"number",begin:"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?"};return{name:"Apache config",aliases:["apacheconf"],case_insensitive:!0,contains:[e.HASH_COMMENT_MODE,{className:"section",begin:"",contains:[n,{className:"number",begin:":\\d{1,5}"},e.inherit(e.QUOTE_STRING_MODE,{relevance:0})]},{className:"attribute",begin:/\w+/,relevance:0,keywords:{nomarkup:"order deny allow setenv rewriterule rewriteengine rewritecond documentroot sethandler errordocument loadmodule options header listen serverroot servername"},starts:{end:/$/,relevance:0,keywords:{literal:"on off all deny allow"},contains:[{className:"meta",begin:"\\s\\[",end:"\\]$"},{className:"variable",begin:"[\\$%]\\{",end:"\\}",contains:["self",{className:"number",begin:"[\\$%]\\d+"}]},n,{className:"number",begin:"\\d+"},e.QUOTE_STRING_MODE]}}],illegal:/\S/}}}());hljs.registerLanguage("java",function(){"use strict";function e(e){return e?"string"==typeof e?e:e.source:null}function n(e){return a("(",e,")?")}function a(...n){return n.map(n=>e(n)).join("")}function s(...n){return"("+n.map(n=>e(n)).join("|")+")"}return function(e){var t="false synchronized int abstract float private char boolean var static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",i={className:"meta",begin:"@[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",contains:[{begin:/\(/,end:/\)/,contains:["self"]}]},r=e=>a("[",e,"]+([",e,"_]*[",e,"]+)?"),c={className:"number",variants:[{begin:`\\b(0[bB]${r("01")})[lL]?`},{begin:`\\b(0${r("0-7")})[dDfFlL]?`},{begin:a(/\b0[xX]/,s(a(r("a-fA-F0-9"),/\./,r("a-fA-F0-9")),a(r("a-fA-F0-9"),/\.?/),a(/\./,r("a-fA-F0-9"))),/([pP][+-]?(\d+))?/,/[fFdDlL]?/)},{begin:a(/\b/,s(a(/\d*\./,r("\\d")),r("\\d")),/[eE][+-]?[\d]+[dDfF]?/)},{begin:a(/\b/,r(/\d/),n(/\.?/),n(r(/\d/)),/[dDfFlL]?/)}],relevance:0};return{name:"Java",aliases:["jsp"],keywords:t,illegal:/<\/|#/,contains:[e.COMMENT("/\\*\\*","\\*/",{relevance:0,contains:[{begin:/\w+@/,relevance:0},{className:"doctag",begin:"@[A-Za-z]+"}]}),e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,{className:"class",beginKeywords:"class interface",end:/[{;=]/,excludeEnd:!0,keywords:"class interface",illegal:/[:"\[\]]/,contains:[{beginKeywords:"extends implements"},e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"new throw return else",relevance:0},{className:"function",begin:"([À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*(<[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*(\\s*,\\s*[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*)*>)?\\s+)+"+e.UNDERSCORE_IDENT_RE+"\\s*\\(",returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:t,contains:[{begin:e.UNDERSCORE_IDENT_RE+"\\s*\\(",returnBegin:!0,relevance:0,contains:[e.UNDERSCORE_TITLE_MODE]},{className:"params",begin:/\(/,end:/\)/,keywords:t,relevance:0,contains:[i,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,e.C_NUMBER_MODE,e.C_BLOCK_COMMENT_MODE]},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},c,i]}}}());hljs.registerLanguage("x86asm",function(){"use strict";return function(s){return{name:"Intel x86 Assembly",case_insensitive:!0,keywords:{$pattern:"[.%]?"+s.IDENT_RE,keyword:"lock rep repe repz repne repnz xaquire xrelease bnd nobnd aaa aad aam aas adc add and arpl bb0_reset bb1_reset bound bsf bsr bswap bt btc btr bts call cbw cdq cdqe clc cld cli clts cmc cmp cmpsb cmpsd cmpsq cmpsw cmpxchg cmpxchg486 cmpxchg8b cmpxchg16b cpuid cpu_read cpu_write cqo cwd cwde daa das dec div dmint emms enter equ f2xm1 fabs fadd faddp fbld fbstp fchs fclex fcmovb fcmovbe fcmove fcmovnb fcmovnbe fcmovne fcmovnu fcmovu fcom fcomi fcomip fcomp fcompp fcos fdecstp fdisi fdiv fdivp fdivr fdivrp femms feni ffree ffreep fiadd ficom ficomp fidiv fidivr fild fimul fincstp finit fist fistp fisttp fisub fisubr fld fld1 fldcw fldenv fldl2e fldl2t fldlg2 fldln2 fldpi fldz fmul fmulp fnclex fndisi fneni fninit fnop fnsave fnstcw fnstenv fnstsw fpatan fprem fprem1 fptan frndint frstor fsave fscale fsetpm fsin fsincos fsqrt fst fstcw fstenv fstp fstsw fsub fsubp fsubr fsubrp ftst fucom fucomi fucomip fucomp fucompp fxam fxch fxtract fyl2x fyl2xp1 hlt ibts icebp idiv imul in inc incbin insb insd insw int int01 int1 int03 int3 into invd invpcid invlpg invlpga iret iretd iretq iretw jcxz jecxz jrcxz jmp jmpe lahf lar lds lea leave les lfence lfs lgdt lgs lidt lldt lmsw loadall loadall286 lodsb lodsd lodsq lodsw loop loope loopne loopnz loopz lsl lss ltr mfence monitor mov movd movq movsb movsd movsq movsw movsx movsxd movzx mul mwait neg nop not or out outsb outsd outsw packssdw packsswb packuswb paddb paddd paddsb paddsiw paddsw paddusb paddusw paddw pand pandn pause paveb pavgusb pcmpeqb pcmpeqd pcmpeqw pcmpgtb pcmpgtd pcmpgtw pdistib pf2id pfacc pfadd pfcmpeq pfcmpge pfcmpgt pfmax pfmin pfmul pfrcp pfrcpit1 pfrcpit2 pfrsqit1 pfrsqrt pfsub pfsubr pi2fd pmachriw pmaddwd pmagw pmulhriw pmulhrwa pmulhrwc pmulhw pmullw pmvgezb pmvlzb pmvnzb pmvzb pop popa popad popaw popf popfd popfq popfw por prefetch prefetchw pslld psllq psllw psrad psraw psrld psrlq psrlw psubb psubd psubsb psubsiw psubsw psubusb psubusw psubw punpckhbw punpckhdq punpckhwd punpcklbw punpckldq punpcklwd push pusha pushad pushaw pushf pushfd pushfq pushfw pxor rcl rcr rdshr rdmsr rdpmc rdtsc rdtscp ret retf retn rol ror rdm rsdc rsldt rsm rsts sahf sal salc sar sbb scasb scasd scasq scasw sfence sgdt shl shld shr shrd sidt sldt skinit smi smint smintold smsw stc std sti stosb stosd stosq stosw str sub svdc svldt svts swapgs syscall sysenter sysexit sysret test ud0 ud1 ud2b ud2 ud2a umov verr verw fwait wbinvd wrshr wrmsr xadd xbts xchg xlatb xlat xor cmove cmovz cmovne cmovnz cmova cmovnbe cmovae cmovnb cmovb cmovnae cmovbe cmovna cmovg cmovnle cmovge cmovnl cmovl cmovnge cmovle cmovng cmovc cmovnc cmovo cmovno cmovs cmovns cmovp cmovpe cmovnp cmovpo je jz jne jnz ja jnbe jae jnb jb jnae jbe jna jg jnle jge jnl jl jnge jle jng jc jnc jo jno js jns jpo jnp jpe jp sete setz setne setnz seta setnbe setae setnb setnc setb setnae setcset setbe setna setg setnle setge setnl setl setnge setle setng sets setns seto setno setpe setp setpo setnp addps addss andnps andps cmpeqps cmpeqss cmpleps cmpless cmpltps cmpltss cmpneqps cmpneqss cmpnleps cmpnless cmpnltps cmpnltss cmpordps cmpordss cmpunordps cmpunordss cmpps cmpss comiss cvtpi2ps cvtps2pi cvtsi2ss cvtss2si cvttps2pi cvttss2si divps divss ldmxcsr maxps maxss minps minss movaps movhps movlhps movlps movhlps movmskps movntps movss movups mulps mulss orps rcpps rcpss rsqrtps rsqrtss shufps sqrtps sqrtss stmxcsr subps subss ucomiss unpckhps unpcklps xorps fxrstor fxrstor64 fxsave fxsave64 xgetbv xsetbv xsave xsave64 xsaveopt xsaveopt64 xrstor xrstor64 prefetchnta prefetcht0 prefetcht1 prefetcht2 maskmovq movntq pavgb pavgw pextrw pinsrw pmaxsw pmaxub pminsw pminub pmovmskb pmulhuw psadbw pshufw pf2iw pfnacc pfpnacc pi2fw pswapd maskmovdqu clflush movntdq movnti movntpd movdqa movdqu movdq2q movq2dq paddq pmuludq pshufd pshufhw pshuflw pslldq psrldq psubq punpckhqdq punpcklqdq addpd addsd andnpd andpd cmpeqpd cmpeqsd cmplepd cmplesd cmpltpd cmpltsd cmpneqpd cmpneqsd cmpnlepd cmpnlesd cmpnltpd cmpnltsd cmpordpd cmpordsd cmpunordpd cmpunordsd cmppd comisd cvtdq2pd cvtdq2ps cvtpd2dq cvtpd2pi cvtpd2ps cvtpi2pd cvtps2dq cvtps2pd cvtsd2si cvtsd2ss cvtsi2sd cvtss2sd cvttpd2pi cvttpd2dq cvttps2dq cvttsd2si divpd divsd maxpd maxsd minpd minsd movapd movhpd movlpd movmskpd movupd mulpd mulsd orpd shufpd sqrtpd sqrtsd subpd subsd ucomisd unpckhpd unpcklpd xorpd addsubpd addsubps haddpd haddps hsubpd hsubps lddqu movddup movshdup movsldup clgi stgi vmcall vmclear vmfunc vmlaunch vmload vmmcall vmptrld vmptrst vmread vmresume vmrun vmsave vmwrite vmxoff vmxon invept invvpid pabsb pabsw pabsd palignr phaddw phaddd phaddsw phsubw phsubd phsubsw pmaddubsw pmulhrsw pshufb psignb psignw psignd extrq insertq movntsd movntss lzcnt blendpd blendps blendvpd blendvps dppd dpps extractps insertps movntdqa mpsadbw packusdw pblendvb pblendw pcmpeqq pextrb pextrd pextrq phminposuw pinsrb pinsrd pinsrq pmaxsb pmaxsd pmaxud pmaxuw pminsb pminsd pminud pminuw pmovsxbw pmovsxbd pmovsxbq pmovsxwd pmovsxwq pmovsxdq pmovzxbw pmovzxbd pmovzxbq pmovzxwd pmovzxwq pmovzxdq pmuldq pmulld ptest roundpd roundps roundsd roundss crc32 pcmpestri pcmpestrm pcmpistri pcmpistrm pcmpgtq popcnt getsec pfrcpv pfrsqrtv movbe aesenc aesenclast aesdec aesdeclast aesimc aeskeygenassist vaesenc vaesenclast vaesdec vaesdeclast vaesimc vaeskeygenassist vaddpd vaddps vaddsd vaddss vaddsubpd vaddsubps vandpd vandps vandnpd vandnps vblendpd vblendps vblendvpd vblendvps vbroadcastss vbroadcastsd vbroadcastf128 vcmpeq_ospd vcmpeqpd vcmplt_ospd vcmpltpd vcmple_ospd vcmplepd vcmpunord_qpd vcmpunordpd vcmpneq_uqpd vcmpneqpd vcmpnlt_uspd vcmpnltpd vcmpnle_uspd vcmpnlepd vcmpord_qpd vcmpordpd vcmpeq_uqpd vcmpnge_uspd vcmpngepd vcmpngt_uspd vcmpngtpd vcmpfalse_oqpd vcmpfalsepd vcmpneq_oqpd vcmpge_ospd vcmpgepd vcmpgt_ospd vcmpgtpd vcmptrue_uqpd vcmptruepd vcmplt_oqpd vcmple_oqpd vcmpunord_spd vcmpneq_uspd vcmpnlt_uqpd vcmpnle_uqpd vcmpord_spd vcmpeq_uspd vcmpnge_uqpd vcmpngt_uqpd vcmpfalse_ospd vcmpneq_ospd vcmpge_oqpd vcmpgt_oqpd vcmptrue_uspd vcmppd vcmpeq_osps vcmpeqps vcmplt_osps vcmpltps vcmple_osps vcmpleps vcmpunord_qps vcmpunordps vcmpneq_uqps vcmpneqps vcmpnlt_usps vcmpnltps vcmpnle_usps vcmpnleps vcmpord_qps vcmpordps vcmpeq_uqps vcmpnge_usps vcmpngeps vcmpngt_usps vcmpngtps vcmpfalse_oqps vcmpfalseps vcmpneq_oqps vcmpge_osps vcmpgeps vcmpgt_osps vcmpgtps vcmptrue_uqps vcmptrueps vcmplt_oqps vcmple_oqps vcmpunord_sps vcmpneq_usps vcmpnlt_uqps vcmpnle_uqps vcmpord_sps vcmpeq_usps vcmpnge_uqps vcmpngt_uqps vcmpfalse_osps vcmpneq_osps vcmpge_oqps vcmpgt_oqps vcmptrue_usps vcmpps vcmpeq_ossd vcmpeqsd vcmplt_ossd vcmpltsd vcmple_ossd vcmplesd vcmpunord_qsd vcmpunordsd vcmpneq_uqsd vcmpneqsd vcmpnlt_ussd vcmpnltsd vcmpnle_ussd vcmpnlesd vcmpord_qsd vcmpordsd vcmpeq_uqsd vcmpnge_ussd vcmpngesd vcmpngt_ussd vcmpngtsd vcmpfalse_oqsd vcmpfalsesd vcmpneq_oqsd vcmpge_ossd vcmpgesd vcmpgt_ossd vcmpgtsd vcmptrue_uqsd vcmptruesd vcmplt_oqsd vcmple_oqsd vcmpunord_ssd vcmpneq_ussd vcmpnlt_uqsd vcmpnle_uqsd vcmpord_ssd vcmpeq_ussd vcmpnge_uqsd vcmpngt_uqsd vcmpfalse_ossd vcmpneq_ossd vcmpge_oqsd vcmpgt_oqsd vcmptrue_ussd vcmpsd vcmpeq_osss vcmpeqss vcmplt_osss vcmpltss vcmple_osss vcmpless vcmpunord_qss vcmpunordss vcmpneq_uqss vcmpneqss vcmpnlt_usss vcmpnltss vcmpnle_usss vcmpnless vcmpord_qss vcmpordss vcmpeq_uqss vcmpnge_usss vcmpngess vcmpngt_usss vcmpngtss vcmpfalse_oqss vcmpfalsess vcmpneq_oqss vcmpge_osss vcmpgess vcmpgt_osss vcmpgtss vcmptrue_uqss vcmptruess vcmplt_oqss vcmple_oqss vcmpunord_sss vcmpneq_usss vcmpnlt_uqss vcmpnle_uqss vcmpord_sss vcmpeq_usss vcmpnge_uqss vcmpngt_uqss vcmpfalse_osss vcmpneq_osss vcmpge_oqss vcmpgt_oqss vcmptrue_usss vcmpss vcomisd vcomiss vcvtdq2pd vcvtdq2ps vcvtpd2dq vcvtpd2ps vcvtps2dq vcvtps2pd vcvtsd2si vcvtsd2ss vcvtsi2sd vcvtsi2ss vcvtss2sd vcvtss2si vcvttpd2dq vcvttps2dq vcvttsd2si vcvttss2si vdivpd vdivps vdivsd vdivss vdppd vdpps vextractf128 vextractps vhaddpd vhaddps vhsubpd vhsubps vinsertf128 vinsertps vlddqu vldqqu vldmxcsr vmaskmovdqu vmaskmovps vmaskmovpd vmaxpd vmaxps vmaxsd vmaxss vminpd vminps vminsd vminss vmovapd vmovaps vmovd vmovq vmovddup vmovdqa vmovqqa vmovdqu vmovqqu vmovhlps vmovhpd vmovhps vmovlhps vmovlpd vmovlps vmovmskpd vmovmskps vmovntdq vmovntqq vmovntdqa vmovntpd vmovntps vmovsd vmovshdup vmovsldup vmovss vmovupd vmovups vmpsadbw vmulpd vmulps vmulsd vmulss vorpd vorps vpabsb vpabsw vpabsd vpacksswb vpackssdw vpackuswb vpackusdw vpaddb vpaddw vpaddd vpaddq vpaddsb vpaddsw vpaddusb vpaddusw vpalignr vpand vpandn vpavgb vpavgw vpblendvb vpblendw vpcmpestri vpcmpestrm vpcmpistri vpcmpistrm vpcmpeqb vpcmpeqw vpcmpeqd vpcmpeqq vpcmpgtb vpcmpgtw vpcmpgtd vpcmpgtq vpermilpd vpermilps vperm2f128 vpextrb vpextrw vpextrd vpextrq vphaddw vphaddd vphaddsw vphminposuw vphsubw vphsubd vphsubsw vpinsrb vpinsrw vpinsrd vpinsrq vpmaddwd vpmaddubsw vpmaxsb vpmaxsw vpmaxsd vpmaxub vpmaxuw vpmaxud vpminsb vpminsw vpminsd vpminub vpminuw vpminud vpmovmskb vpmovsxbw vpmovsxbd vpmovsxbq vpmovsxwd vpmovsxwq vpmovsxdq vpmovzxbw vpmovzxbd vpmovzxbq vpmovzxwd vpmovzxwq vpmovzxdq vpmulhuw vpmulhrsw vpmulhw vpmullw vpmulld vpmuludq vpmuldq vpor vpsadbw vpshufb vpshufd vpshufhw vpshuflw vpsignb vpsignw vpsignd vpslldq vpsrldq vpsllw vpslld vpsllq vpsraw vpsrad vpsrlw vpsrld vpsrlq vptest vpsubb vpsubw vpsubd vpsubq vpsubsb vpsubsw vpsubusb vpsubusw vpunpckhbw vpunpckhwd vpunpckhdq vpunpckhqdq vpunpcklbw vpunpcklwd vpunpckldq vpunpcklqdq vpxor vrcpps vrcpss vrsqrtps vrsqrtss vroundpd vroundps vroundsd vroundss vshufpd vshufps vsqrtpd vsqrtps vsqrtsd vsqrtss vstmxcsr vsubpd vsubps vsubsd vsubss vtestps vtestpd vucomisd vucomiss vunpckhpd vunpckhps vunpcklpd vunpcklps vxorpd vxorps vzeroall vzeroupper pclmullqlqdq pclmulhqlqdq pclmullqhqdq pclmulhqhqdq pclmulqdq vpclmullqlqdq vpclmulhqlqdq vpclmullqhqdq vpclmulhqhqdq vpclmulqdq vfmadd132ps vfmadd132pd vfmadd312ps vfmadd312pd vfmadd213ps vfmadd213pd vfmadd123ps vfmadd123pd vfmadd231ps vfmadd231pd vfmadd321ps vfmadd321pd vfmaddsub132ps vfmaddsub132pd vfmaddsub312ps vfmaddsub312pd vfmaddsub213ps vfmaddsub213pd vfmaddsub123ps vfmaddsub123pd vfmaddsub231ps vfmaddsub231pd vfmaddsub321ps vfmaddsub321pd vfmsub132ps vfmsub132pd vfmsub312ps vfmsub312pd vfmsub213ps vfmsub213pd vfmsub123ps vfmsub123pd vfmsub231ps vfmsub231pd vfmsub321ps vfmsub321pd vfmsubadd132ps vfmsubadd132pd vfmsubadd312ps vfmsubadd312pd vfmsubadd213ps vfmsubadd213pd vfmsubadd123ps vfmsubadd123pd vfmsubadd231ps vfmsubadd231pd vfmsubadd321ps vfmsubadd321pd vfnmadd132ps vfnmadd132pd vfnmadd312ps vfnmadd312pd vfnmadd213ps vfnmadd213pd vfnmadd123ps vfnmadd123pd vfnmadd231ps vfnmadd231pd vfnmadd321ps vfnmadd321pd vfnmsub132ps vfnmsub132pd vfnmsub312ps vfnmsub312pd vfnmsub213ps vfnmsub213pd vfnmsub123ps vfnmsub123pd vfnmsub231ps vfnmsub231pd vfnmsub321ps vfnmsub321pd vfmadd132ss vfmadd132sd vfmadd312ss vfmadd312sd vfmadd213ss vfmadd213sd vfmadd123ss vfmadd123sd vfmadd231ss vfmadd231sd vfmadd321ss vfmadd321sd vfmsub132ss vfmsub132sd vfmsub312ss vfmsub312sd vfmsub213ss vfmsub213sd vfmsub123ss vfmsub123sd vfmsub231ss vfmsub231sd vfmsub321ss vfmsub321sd vfnmadd132ss vfnmadd132sd vfnmadd312ss vfnmadd312sd vfnmadd213ss vfnmadd213sd vfnmadd123ss vfnmadd123sd vfnmadd231ss vfnmadd231sd vfnmadd321ss vfnmadd321sd vfnmsub132ss vfnmsub132sd vfnmsub312ss vfnmsub312sd vfnmsub213ss vfnmsub213sd vfnmsub123ss vfnmsub123sd vfnmsub231ss vfnmsub231sd vfnmsub321ss vfnmsub321sd rdfsbase rdgsbase rdrand wrfsbase wrgsbase vcvtph2ps vcvtps2ph adcx adox rdseed clac stac xstore xcryptecb xcryptcbc xcryptctr xcryptcfb xcryptofb montmul xsha1 xsha256 llwpcb slwpcb lwpval lwpins vfmaddpd vfmaddps vfmaddsd vfmaddss vfmaddsubpd vfmaddsubps vfmsubaddpd vfmsubaddps vfmsubpd vfmsubps vfmsubsd vfmsubss vfnmaddpd vfnmaddps vfnmaddsd vfnmaddss vfnmsubpd vfnmsubps vfnmsubsd vfnmsubss vfrczpd vfrczps vfrczsd vfrczss vpcmov vpcomb vpcomd vpcomq vpcomub vpcomud vpcomuq vpcomuw vpcomw vphaddbd vphaddbq vphaddbw vphadddq vphaddubd vphaddubq vphaddubw vphaddudq vphadduwd vphadduwq vphaddwd vphaddwq vphsubbw vphsubdq vphsubwd vpmacsdd vpmacsdqh vpmacsdql vpmacssdd vpmacssdqh vpmacssdql vpmacsswd vpmacssww vpmacswd vpmacsww vpmadcsswd vpmadcswd vpperm vprotb vprotd vprotq vprotw vpshab vpshad vpshaq vpshaw vpshlb vpshld vpshlq vpshlw vbroadcasti128 vpblendd vpbroadcastb vpbroadcastw vpbroadcastd vpbroadcastq vpermd vpermpd vpermps vpermq vperm2i128 vextracti128 vinserti128 vpmaskmovd vpmaskmovq vpsllvd vpsllvq vpsravd vpsrlvd vpsrlvq vgatherdpd vgatherqpd vgatherdps vgatherqps vpgatherdd vpgatherqd vpgatherdq vpgatherqq xabort xbegin xend xtest andn bextr blci blcic blsi blsic blcfill blsfill blcmsk blsmsk blsr blcs bzhi mulx pdep pext rorx sarx shlx shrx tzcnt tzmsk t1mskc valignd valignq vblendmpd vblendmps vbroadcastf32x4 vbroadcastf64x4 vbroadcasti32x4 vbroadcasti64x4 vcompresspd vcompressps vcvtpd2udq vcvtps2udq vcvtsd2usi vcvtss2usi vcvttpd2udq vcvttps2udq vcvttsd2usi vcvttss2usi vcvtudq2pd vcvtudq2ps vcvtusi2sd vcvtusi2ss vexpandpd vexpandps vextractf32x4 vextractf64x4 vextracti32x4 vextracti64x4 vfixupimmpd vfixupimmps vfixupimmsd vfixupimmss vgetexppd vgetexpps vgetexpsd vgetexpss vgetmantpd vgetmantps vgetmantsd vgetmantss vinsertf32x4 vinsertf64x4 vinserti32x4 vinserti64x4 vmovdqa32 vmovdqa64 vmovdqu32 vmovdqu64 vpabsq vpandd vpandnd vpandnq vpandq vpblendmd vpblendmq vpcmpltd vpcmpled vpcmpneqd vpcmpnltd vpcmpnled vpcmpd vpcmpltq vpcmpleq vpcmpneqq vpcmpnltq vpcmpnleq vpcmpq vpcmpequd vpcmpltud vpcmpleud vpcmpnequd vpcmpnltud vpcmpnleud vpcmpud vpcmpequq vpcmpltuq vpcmpleuq vpcmpnequq vpcmpnltuq vpcmpnleuq vpcmpuq vpcompressd vpcompressq vpermi2d vpermi2pd vpermi2ps vpermi2q vpermt2d vpermt2pd vpermt2ps vpermt2q vpexpandd vpexpandq vpmaxsq vpmaxuq vpminsq vpminuq vpmovdb vpmovdw vpmovqb vpmovqd vpmovqw vpmovsdb vpmovsdw vpmovsqb vpmovsqd vpmovsqw vpmovusdb vpmovusdw vpmovusqb vpmovusqd vpmovusqw vpord vporq vprold vprolq vprolvd vprolvq vprord vprorq vprorvd vprorvq vpscatterdd vpscatterdq vpscatterqd vpscatterqq vpsraq vpsravq vpternlogd vpternlogq vptestmd vptestmq vptestnmd vptestnmq vpxord vpxorq vrcp14pd vrcp14ps vrcp14sd vrcp14ss vrndscalepd vrndscaleps vrndscalesd vrndscaless vrsqrt14pd vrsqrt14ps vrsqrt14sd vrsqrt14ss vscalefpd vscalefps vscalefsd vscalefss vscatterdpd vscatterdps vscatterqpd vscatterqps vshuff32x4 vshuff64x2 vshufi32x4 vshufi64x2 kandnw kandw kmovw knotw kortestw korw kshiftlw kshiftrw kunpckbw kxnorw kxorw vpbroadcastmb2q vpbroadcastmw2d vpconflictd vpconflictq vplzcntd vplzcntq vexp2pd vexp2ps vrcp28pd vrcp28ps vrcp28sd vrcp28ss vrsqrt28pd vrsqrt28ps vrsqrt28sd vrsqrt28ss vgatherpf0dpd vgatherpf0dps vgatherpf0qpd vgatherpf0qps vgatherpf1dpd vgatherpf1dps vgatherpf1qpd vgatherpf1qps vscatterpf0dpd vscatterpf0dps vscatterpf0qpd vscatterpf0qps vscatterpf1dpd vscatterpf1dps vscatterpf1qpd vscatterpf1qps prefetchwt1 bndmk bndcl bndcu bndcn bndmov bndldx bndstx sha1rnds4 sha1nexte sha1msg1 sha1msg2 sha256rnds2 sha256msg1 sha256msg2 hint_nop0 hint_nop1 hint_nop2 hint_nop3 hint_nop4 hint_nop5 hint_nop6 hint_nop7 hint_nop8 hint_nop9 hint_nop10 hint_nop11 hint_nop12 hint_nop13 hint_nop14 hint_nop15 hint_nop16 hint_nop17 hint_nop18 hint_nop19 hint_nop20 hint_nop21 hint_nop22 hint_nop23 hint_nop24 hint_nop25 hint_nop26 hint_nop27 hint_nop28 hint_nop29 hint_nop30 hint_nop31 hint_nop32 hint_nop33 hint_nop34 hint_nop35 hint_nop36 hint_nop37 hint_nop38 hint_nop39 hint_nop40 hint_nop41 hint_nop42 hint_nop43 hint_nop44 hint_nop45 hint_nop46 hint_nop47 hint_nop48 hint_nop49 hint_nop50 hint_nop51 hint_nop52 hint_nop53 hint_nop54 hint_nop55 hint_nop56 hint_nop57 hint_nop58 hint_nop59 hint_nop60 hint_nop61 hint_nop62 hint_nop63",built_in:"ip eip rip al ah bl bh cl ch dl dh sil dil bpl spl r8b r9b r10b r11b r12b r13b r14b r15b ax bx cx dx si di bp sp r8w r9w r10w r11w r12w r13w r14w r15w eax ebx ecx edx esi edi ebp esp eip r8d r9d r10d r11d r12d r13d r14d r15d rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15 cs ds es fs gs ss st st0 st1 st2 st3 st4 st5 st6 st7 mm0 mm1 mm2 mm3 mm4 mm5 mm6 mm7 xmm0 xmm1 xmm2 xmm3 xmm4 xmm5 xmm6 xmm7 xmm8 xmm9 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15 xmm16 xmm17 xmm18 xmm19 xmm20 xmm21 xmm22 xmm23 xmm24 xmm25 xmm26 xmm27 xmm28 xmm29 xmm30 xmm31 ymm0 ymm1 ymm2 ymm3 ymm4 ymm5 ymm6 ymm7 ymm8 ymm9 ymm10 ymm11 ymm12 ymm13 ymm14 ymm15 ymm16 ymm17 ymm18 ymm19 ymm20 ymm21 ymm22 ymm23 ymm24 ymm25 ymm26 ymm27 ymm28 ymm29 ymm30 ymm31 zmm0 zmm1 zmm2 zmm3 zmm4 zmm5 zmm6 zmm7 zmm8 zmm9 zmm10 zmm11 zmm12 zmm13 zmm14 zmm15 zmm16 zmm17 zmm18 zmm19 zmm20 zmm21 zmm22 zmm23 zmm24 zmm25 zmm26 zmm27 zmm28 zmm29 zmm30 zmm31 k0 k1 k2 k3 k4 k5 k6 k7 bnd0 bnd1 bnd2 bnd3 cr0 cr1 cr2 cr3 cr4 cr8 dr0 dr1 dr2 dr3 dr8 tr3 tr4 tr5 tr6 tr7 r0 r1 r2 r3 r4 r5 r6 r7 r0b r1b r2b r3b r4b r5b r6b r7b r0w r1w r2w r3w r4w r5w r6w r7w r0d r1d r2d r3d r4d r5d r6d r7d r0h r1h r2h r3h r0l r1l r2l r3l r4l r5l r6l r7l r8l r9l r10l r11l r12l r13l r14l r15l db dw dd dq dt ddq do dy dz resb resw resd resq rest resdq reso resy resz incbin equ times byte word dword qword nosplit rel abs seg wrt strict near far a32 ptr",meta:"%define %xdefine %+ %undef %defstr %deftok %assign %strcat %strlen %substr %rotate %elif %else %endif %if %ifmacro %ifctx %ifidn %ifidni %ifid %ifnum %ifstr %iftoken %ifempty %ifenv %error %warning %fatal %rep %endrep %include %push %pop %repl %pathsearch %depend %use %arg %stacksize %local %line %comment %endcomment .nolist __FILE__ __LINE__ __SECT__ __BITS__ __OUTPUT_FORMAT__ __DATE__ __TIME__ __DATE_NUM__ __TIME_NUM__ __UTC_DATE__ __UTC_TIME__ __UTC_DATE_NUM__ __UTC_TIME_NUM__ __PASS__ struc endstruc istruc at iend align alignb sectalign daz nodaz up down zero default option assume public bits use16 use32 use64 default section segment absolute extern global common cpu float __utf16__ __utf16le__ __utf16be__ __utf32__ __utf32le__ __utf32be__ __float8__ __float16__ __float32__ __float64__ __float80m__ __float80e__ __float128l__ __float128h__ __Infinity__ __QNaN__ __SNaN__ Inf NaN QNaN SNaN float8 float16 float32 float64 float80m float80e float128l float128h __FLOAT_DAZ__ __FLOAT_ROUND__ __FLOAT__"},contains:[s.COMMENT(";","$",{relevance:0}),{className:"number",variants:[{begin:"\\b(?:([0-9][0-9_]*)?\\.[0-9_]*(?:[eE][+-]?[0-9_]+)?|(0[Xx])?[0-9][0-9_]*\\.?[0-9_]*(?:[pP](?:[+-]?[0-9_]+)?)?)\\b",relevance:0},{begin:"\\$[0-9][0-9A-Fa-f]*",relevance:0},{begin:"\\b(?:[0-9A-Fa-f][0-9A-Fa-f_]*[Hh]|[0-9][0-9_]*[DdTt]?|[0-7][0-7_]*[QqOo]|[0-1][0-1_]*[BbYy])\\b"},{begin:"\\b(?:0[Xx][0-9A-Fa-f_]+|0[DdTt][0-9_]+|0[QqOo][0-7_]+|0[BbYy][0-1_]+)\\b"}]},s.QUOTE_STRING_MODE,{className:"string",variants:[{begin:"'",end:"[^\\\\]'"},{begin:"`",end:"[^\\\\]`"}],relevance:0},{className:"symbol",variants:[{begin:"^\\s*[A-Za-z._?][A-Za-z0-9_$#@~.?]*(:|\\s+label)"},{begin:"^\\s*%%[A-Za-z0-9_$#@~.?]*:"}],relevance:0},{className:"subst",begin:"%[0-9]+",relevance:0},{className:"subst",begin:"%!S+",relevance:0},{className:"meta",begin:/^\s*\.[\w_-]+/}]}}}());hljs.registerLanguage("kotlin",function(){"use strict";return function(e){var n={keyword:"abstract as val var vararg get set class object open private protected public noinline crossinline dynamic final enum if else do while for when throw try catch finally import package is in fun override companion reified inline lateinit init interface annotation data sealed internal infix operator out by constructor super tailrec where const inner suspend typealias external expect actual trait volatile transient native default",built_in:"Byte Short Char Int Long Boolean Float Double Void Unit Nothing",literal:"true false null"},a={className:"symbol",begin:e.UNDERSCORE_IDENT_RE+"@"},i={className:"subst",begin:"\\${",end:"}",contains:[e.C_NUMBER_MODE]},s={className:"variable",begin:"\\$"+e.UNDERSCORE_IDENT_RE},t={className:"string",variants:[{begin:'"""',end:'"""(?=[^"])',contains:[s,i]},{begin:"'",end:"'",illegal:/\n/,contains:[e.BACKSLASH_ESCAPE]},{begin:'"',end:'"',illegal:/\n/,contains:[e.BACKSLASH_ESCAPE,s,i]}]};i.contains.push(t);var r={className:"meta",begin:"@(?:file|property|field|get|set|receiver|param|setparam|delegate)\\s*:(?:\\s*"+e.UNDERSCORE_IDENT_RE+")?"},l={className:"meta",begin:"@"+e.UNDERSCORE_IDENT_RE,contains:[{begin:/\(/,end:/\)/,contains:[e.inherit(t,{className:"meta-string"})]}]},c=e.COMMENT("/\\*","\\*/",{contains:[e.C_BLOCK_COMMENT_MODE]}),o={variants:[{className:"type",begin:e.UNDERSCORE_IDENT_RE},{begin:/\(/,end:/\)/,contains:[]}]},d=o;return d.variants[1].contains=[o],o.variants[1].contains=[d],{name:"Kotlin",aliases:["kt"],keywords:n,contains:[e.COMMENT("/\\*\\*","\\*/",{relevance:0,contains:[{className:"doctag",begin:"@[A-Za-z]+"}]}),e.C_LINE_COMMENT_MODE,c,{className:"keyword",begin:/\b(break|continue|return|this)\b/,starts:{contains:[{className:"symbol",begin:/@\w+/}]}},a,r,l,{className:"function",beginKeywords:"fun",end:"[(]|$",returnBegin:!0,excludeEnd:!0,keywords:n,illegal:/fun\s+(<.*>)?[^\s\(]+(\s+[^\s\(]+)\s*=/,relevance:5,contains:[{begin:e.UNDERSCORE_IDENT_RE+"\\s*\\(",returnBegin:!0,relevance:0,contains:[e.UNDERSCORE_TITLE_MODE]},{className:"type",begin://,keywords:"reified",relevance:0},{className:"params",begin:/\(/,end:/\)/,endsParent:!0,keywords:n,relevance:0,contains:[{begin:/:/,end:/[=,\/]/,endsWithParent:!0,contains:[o,e.C_LINE_COMMENT_MODE,c],relevance:0},e.C_LINE_COMMENT_MODE,c,r,l,t,e.C_NUMBER_MODE]},c]},{className:"class",beginKeywords:"class interface trait",end:/[:\{(]|$/,excludeEnd:!0,illegal:"extends implements",contains:[{beginKeywords:"public protected internal private constructor"},e.UNDERSCORE_TITLE_MODE,{className:"type",begin://,excludeBegin:!0,excludeEnd:!0,relevance:0},{className:"type",begin:/[,:]\s*/,end:/[<\(,]|$/,excludeBegin:!0,returnEnd:!0},r,l]},t,{className:"meta",begin:"^#!/usr/bin/env",end:"$",illegal:"\n"},{className:"number",begin:"\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",relevance:0}]}}}());hljs.registerLanguage("armasm",function(){"use strict";return function(s){const e={variants:[s.COMMENT("^[ \\t]*(?=#)","$",{relevance:0,excludeBegin:!0}),s.COMMENT("[;@]","$",{relevance:0}),s.C_LINE_COMMENT_MODE,s.C_BLOCK_COMMENT_MODE]};return{name:"ARM Assembly",case_insensitive:!0,aliases:["arm"],keywords:{$pattern:"\\.?"+s.IDENT_RE,meta:".2byte .4byte .align .ascii .asciz .balign .byte .code .data .else .end .endif .endm .endr .equ .err .exitm .extern .global .hword .if .ifdef .ifndef .include .irp .long .macro .rept .req .section .set .skip .space .text .word .arm .thumb .code16 .code32 .force_thumb .thumb_func .ltorg ALIAS ALIGN ARM AREA ASSERT ATTR CN CODE CODE16 CODE32 COMMON CP DATA DCB DCD DCDU DCDO DCFD DCFDU DCI DCQ DCQU DCW DCWU DN ELIF ELSE END ENDFUNC ENDIF ENDP ENTRY EQU EXPORT EXPORTAS EXTERN FIELD FILL FUNCTION GBLA GBLL GBLS GET GLOBAL IF IMPORT INCBIN INCLUDE INFO KEEP LCLA LCLL LCLS LTORG MACRO MAP MEND MEXIT NOFP OPT PRESERVE8 PROC QN READONLY RELOC REQUIRE REQUIRE8 RLIST FN ROUT SETA SETL SETS SN SPACE SUBT THUMB THUMBX TTL WHILE WEND ",built_in:"r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 pc lr sp ip sl sb fp a1 a2 a3 a4 v1 v2 v3 v4 v5 v6 v7 v8 f0 f1 f2 f3 f4 f5 f6 f7 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 q0 q1 q2 q3 q4 q5 q6 q7 q8 q9 q10 q11 q12 q13 q14 q15 cpsr_c cpsr_x cpsr_s cpsr_f cpsr_cx cpsr_cxs cpsr_xs cpsr_xsf cpsr_sf cpsr_cxsf spsr_c spsr_x spsr_s spsr_f spsr_cx spsr_cxs spsr_xs spsr_xsf spsr_sf spsr_cxsf s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s20 s21 s22 s23 s24 s25 s26 s27 s28 s29 s30 s31 d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20 d21 d22 d23 d24 d25 d26 d27 d28 d29 d30 d31 {PC} {VAR} {TRUE} {FALSE} {OPT} {CONFIG} {ENDIAN} {CODESIZE} {CPU} {FPU} {ARCHITECTURE} {PCSTOREOFFSET} {ARMASM_VERSION} {INTER} {ROPI} {RWPI} {SWST} {NOSWST} . @"},contains:[{className:"keyword",begin:"\\b(adc|(qd?|sh?|u[qh]?)?add(8|16)?|usada?8|(q|sh?|u[qh]?)?(as|sa)x|and|adrl?|sbc|rs[bc]|asr|b[lx]?|blx|bxj|cbn?z|tb[bh]|bic|bfc|bfi|[su]bfx|bkpt|cdp2?|clz|clrex|cmp|cmn|cpsi[ed]|cps|setend|dbg|dmb|dsb|eor|isb|it[te]{0,3}|lsl|lsr|ror|rrx|ldm(([id][ab])|f[ds])?|ldr((s|ex)?[bhd])?|movt?|mvn|mra|mar|mul|[us]mull|smul[bwt][bt]|smu[as]d|smmul|smmla|mla|umlaal|smlal?([wbt][bt]|d)|mls|smlsl?[ds]|smc|svc|sev|mia([bt]{2}|ph)?|mrr?c2?|mcrr2?|mrs|msr|orr|orn|pkh(tb|bt)|rbit|rev(16|sh)?|sel|[su]sat(16)?|nop|pop|push|rfe([id][ab])?|stm([id][ab])?|str(ex)?[bhd]?|(qd?)?sub|(sh?|q|u[qh]?)?sub(8|16)|[su]xt(a?h|a?b(16)?)|srs([id][ab])?|swpb?|swi|smi|tst|teq|wfe|wfi|yield)(eq|ne|cs|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al|hs|lo)?[sptrx]?(?=\\s)"},e,s.QUOTE_STRING_MODE,{className:"string",begin:"'",end:"[^\\\\]'",relevance:0},{className:"title",begin:"\\|",end:"\\|",illegal:"\\n",relevance:0},{className:"number",variants:[{begin:"[#$=]?0x[0-9a-f]+"},{begin:"[#$=]?0b[01]+"},{begin:"[#$=]\\d+"},{begin:"\\b\\d+"}],relevance:0},{className:"symbol",variants:[{begin:"^[ \\t]*[a-z_\\.\\$][a-z0-9_\\.\\$]+:"},{begin:"^[a-z_\\.\\$][a-z0-9_\\.\\$]+"},{begin:"[=#]\\w+"}],relevance:0}]}}}());hljs.registerLanguage("go",function(){"use strict";return function(e){var n={keyword:"break default func interface select case map struct chan else goto package switch const fallthrough if range type continue for import return var go defer bool byte complex64 complex128 float32 float64 int8 int16 int32 int64 string uint8 uint16 uint32 uint64 int uint uintptr rune",literal:"true false iota nil",built_in:"append cap close complex copy imag len make new panic print println real recover delete"};return{name:"Go",aliases:["golang"],keywords:n,illegal:">>|\.\.\.) /},i={className:"subst",begin:/\{/,end:/\}/,keywords:n,illegal:/#/},s={begin:/\{\{/,relevance:0},r={className:"string",contains:[e.BACKSLASH_ESCAPE],variants:[{begin:/(u|b)?r?'''/,end:/'''/,contains:[e.BACKSLASH_ESCAPE,a],relevance:10},{begin:/(u|b)?r?"""/,end:/"""/,contains:[e.BACKSLASH_ESCAPE,a],relevance:10},{begin:/(fr|rf|f)'''/,end:/'''/,contains:[e.BACKSLASH_ESCAPE,a,s,i]},{begin:/(fr|rf|f)"""/,end:/"""/,contains:[e.BACKSLASH_ESCAPE,a,s,i]},{begin:/(u|r|ur)'/,end:/'/,relevance:10},{begin:/(u|r|ur)"/,end:/"/,relevance:10},{begin:/(b|br)'/,end:/'/},{begin:/(b|br)"/,end:/"/},{begin:/(fr|rf|f)'/,end:/'/,contains:[e.BACKSLASH_ESCAPE,s,i]},{begin:/(fr|rf|f)"/,end:/"/,contains:[e.BACKSLASH_ESCAPE,s,i]},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]},l={className:"number",relevance:0,variants:[{begin:e.BINARY_NUMBER_RE+"[lLjJ]?"},{begin:"\\b(0o[0-7]+)[lLjJ]?"},{begin:e.C_NUMBER_RE+"[lLjJ]?"}]},t={className:"params",variants:[{begin:/\(\s*\)/,skip:!0,className:null},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,contains:["self",a,l,r,e.HASH_COMMENT_MODE]}]};return i.contains=[r,l,a],{name:"Python",aliases:["py","gyp","ipython"],keywords:n,illegal:/(<\/|->|\?)|=>/,contains:[a,l,{beginKeywords:"if",relevance:0},r,e.HASH_COMMENT_MODE,{variants:[{className:"function",beginKeywords:"def"},{className:"class",beginKeywords:"class"}],end:/:/,illegal:/[${=;\n,]/,contains:[e.UNDERSCORE_TITLE_MODE,t,{begin:/->/,endsWithParent:!0,keywords:"None"}]},{className:"meta",begin:/^[\t ]*@/,end:/$/},{begin:/\b(print|exec)\(/}]}}}());hljs.registerLanguage("shell",function(){"use strict";return function(s){return{name:"Shell Session",aliases:["console"],contains:[{className:"meta",begin:"^\\s{0,3}[/\\w\\d\\[\\]()@-]*[>%$#]",starts:{end:"$",subLanguage:"bash"}}]}}}());hljs.registerLanguage("scala",function(){"use strict";return function(e){var n={className:"subst",variants:[{begin:"\\$[A-Za-z0-9_]+"},{begin:"\\${",end:"}"}]},a={className:"string",variants:[{begin:'"',end:'"',illegal:"\\n",contains:[e.BACKSLASH_ESCAPE]},{begin:'"""',end:'"""',relevance:10},{begin:'[a-z]+"',end:'"',illegal:"\\n",contains:[e.BACKSLASH_ESCAPE,n]},{className:"string",begin:'[a-z]+"""',end:'"""',contains:[n],relevance:10}]},s={className:"type",begin:"\\b[A-Z][A-Za-z0-9_]*",relevance:0},t={className:"title",begin:/[^0-9\n\t "'(),.`{}\[\]:;][^\n\t "'(),.`{}\[\]:;]+|[^0-9\n\t "'(),.`{}\[\]:;=]/,relevance:0},i={className:"class",beginKeywords:"class object trait type",end:/[:={\[\n;]/,excludeEnd:!0,contains:[{beginKeywords:"extends with",relevance:10},{begin:/\[/,end:/\]/,excludeBegin:!0,excludeEnd:!0,relevance:0,contains:[s]},{className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,relevance:0,contains:[s]},t]},l={className:"function",beginKeywords:"def",end:/[:={\[(\n;]/,excludeEnd:!0,contains:[t]};return{name:"Scala",keywords:{literal:"true false null",keyword:"type yield lazy override def with val var sealed abstract private trait object if forSome for while throw finally protected extends import final return else break new catch super class case package default try this match continue throws implicit"},contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,{className:"symbol",begin:"'\\w[\\w\\d_]*(?!')"},s,l,i,e.C_NUMBER_MODE,{className:"meta",begin:"@[A-Za-z]+"}]}}}());hljs.registerLanguage("julia",function(){"use strict";return function(e){var r="[A-Za-z_\\u00A1-\\uFFFF][A-Za-z_0-9\\u00A1-\\uFFFF]*",t={$pattern:r,keyword:"in isa where baremodule begin break catch ccall const continue do else elseif end export false finally for function global if import importall let local macro module quote return true try using while type immutable abstract bitstype typealias ",literal:"true false ARGS C_NULL DevNull ENDIAN_BOM ENV I Inf Inf16 Inf32 Inf64 InsertionSort JULIA_HOME LOAD_PATH MergeSort NaN NaN16 NaN32 NaN64 PROGRAM_FILE QuickSort RoundDown RoundFromZero RoundNearest RoundNearestTiesAway RoundNearestTiesUp RoundToZero RoundUp STDERR STDIN STDOUT VERSION catalan e|0 eu|0 eulergamma golden im nothing pi γ π φ ",built_in:"ANY AbstractArray AbstractChannel AbstractFloat AbstractMatrix AbstractRNG AbstractSerializer AbstractSet AbstractSparseArray AbstractSparseMatrix AbstractSparseVector AbstractString AbstractUnitRange AbstractVecOrMat AbstractVector Any ArgumentError Array AssertionError Associative Base64DecodePipe Base64EncodePipe Bidiagonal BigFloat BigInt BitArray BitMatrix BitVector Bool BoundsError BufferStream CachingPool CapturedException CartesianIndex CartesianRange Cchar Cdouble Cfloat Channel Char Cint Cintmax_t Clong Clonglong ClusterManager Cmd CodeInfo Colon Complex Complex128 Complex32 Complex64 CompositeException Condition ConjArray ConjMatrix ConjVector Cptrdiff_t Cshort Csize_t Cssize_t Cstring Cuchar Cuint Cuintmax_t Culong Culonglong Cushort Cwchar_t Cwstring DataType Date DateFormat DateTime DenseArray DenseMatrix DenseVecOrMat DenseVector Diagonal Dict DimensionMismatch Dims DirectIndexString Display DivideError DomainError EOFError EachLine Enum Enumerate ErrorException Exception ExponentialBackOff Expr Factorization FileMonitor Float16 Float32 Float64 Function Future GlobalRef GotoNode HTML Hermitian IO IOBuffer IOContext IOStream IPAddr IPv4 IPv6 IndexCartesian IndexLinear IndexStyle InexactError InitError Int Int128 Int16 Int32 Int64 Int8 IntSet Integer InterruptException InvalidStateException Irrational KeyError LabelNode LinSpace LineNumberNode LoadError LowerTriangular MIME Matrix MersenneTwister Method MethodError MethodTable Module NTuple NewvarNode NullException Nullable Number ObjectIdDict OrdinalRange OutOfMemoryError OverflowError Pair ParseError PartialQuickSort PermutedDimsArray Pipe PollingFileWatcher ProcessExitedException Ptr QuoteNode RandomDevice Range RangeIndex Rational RawFD ReadOnlyMemoryError Real ReentrantLock Ref Regex RegexMatch RemoteChannel RemoteException RevString RoundingMode RowVector SSAValue SegmentationFault SerializationState Set SharedArray SharedMatrix SharedVector Signed SimpleVector Slot SlotNumber SparseMatrixCSC SparseVector StackFrame StackOverflowError StackTrace StepRange StepRangeLen StridedArray StridedMatrix StridedVecOrMat StridedVector String SubArray SubString SymTridiagonal Symbol Symmetric SystemError TCPSocket Task Text TextDisplay Timer Tridiagonal Tuple Type TypeError TypeMapEntry TypeMapLevel TypeName TypeVar TypedSlot UDPSocket UInt UInt128 UInt16 UInt32 UInt64 UInt8 UndefRefError UndefVarError UnicodeError UniformScaling Union UnionAll UnitRange Unsigned UpperTriangular Val Vararg VecElement VecOrMat Vector VersionNumber Void WeakKeyDict WeakRef WorkerConfig WorkerPool "},a={keywords:t,illegal:/<\//},n={className:"subst",begin:/\$\(/,end:/\)/,keywords:t},o={className:"variable",begin:"\\$"+r},i={className:"string",contains:[e.BACKSLASH_ESCAPE,n,o],variants:[{begin:/\w*"""/,end:/"""\w*/,relevance:10},{begin:/\w*"/,end:/"\w*/}]},l={className:"string",contains:[e.BACKSLASH_ESCAPE,n,o],begin:"`",end:"`"},s={className:"meta",begin:"@"+r};return a.name="Julia",a.contains=[{className:"number",begin:/(\b0x[\d_]*(\.[\d_]*)?|0x\.\d[\d_]*)p[-+]?\d+|\b0[box][a-fA-F0-9][a-fA-F0-9_]*|(\b\d[\d_]*(\.[\d_]*)?|\.\d[\d_]*)([eEfF][-+]?\d+)?/,relevance:0},{className:"string",begin:/'(.|\\[xXuU][a-zA-Z0-9]+)'/},i,l,s,{className:"comment",variants:[{begin:"#=",end:"=#",relevance:10},{begin:"#",end:"$"}]},e.HASH_COMMENT_MODE,{className:"keyword",begin:"\\b(((abstract|primitive)\\s+)type|(mutable\\s+)?struct)\\b"},{begin:/<:/}],n.contains=a.contains,a}}());hljs.registerLanguage("php-template",function(){"use strict";return function(n){return{name:"PHP template",subLanguage:"xml",contains:[{begin:/<\?(php|=)?/,end:/\?>/,subLanguage:"php",contains:[{begin:"/\\*",end:"\\*/",skip:!0},{begin:'b"',end:'"',skip:!0},{begin:"b'",end:"'",skip:!0},n.inherit(n.APOS_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0}),n.inherit(n.QUOTE_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0})]}]}}}());hljs.registerLanguage("scss",function(){"use strict";return function(e){var t={className:"variable",begin:"(\\$[a-zA-Z-][a-zA-Z0-9_-]*)\\b"},i={className:"number",begin:"#[0-9A-Fa-f]+"};return e.CSS_NUMBER_MODE,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,e.C_BLOCK_COMMENT_MODE,{name:"SCSS",case_insensitive:!0,illegal:"[=/|']",contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,{className:"selector-id",begin:"\\#[A-Za-z0-9_-]+",relevance:0},{className:"selector-class",begin:"\\.[A-Za-z0-9_-]+",relevance:0},{className:"selector-attr",begin:"\\[",end:"\\]",illegal:"$"},{className:"selector-tag",begin:"\\b(a|abbr|acronym|address|area|article|aside|audio|b|base|big|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|command|datalist|dd|del|details|dfn|div|dl|dt|em|embed|fieldset|figcaption|figure|footer|form|frame|frameset|(h[1-6])|head|header|hgroup|hr|html|i|iframe|img|input|ins|kbd|keygen|label|legend|li|link|map|mark|meta|meter|nav|noframes|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|rp|rt|ruby|samp|script|section|select|small|span|strike|strong|style|sub|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|tt|ul|var|video)\\b",relevance:0},{className:"selector-pseudo",begin:":(visited|valid|root|right|required|read-write|read-only|out-range|optional|only-of-type|only-child|nth-of-type|nth-last-of-type|nth-last-child|nth-child|not|link|left|last-of-type|last-child|lang|invalid|indeterminate|in-range|hover|focus|first-of-type|first-line|first-letter|first-child|first|enabled|empty|disabled|default|checked|before|after|active)"},{className:"selector-pseudo",begin:"::(after|before|choices|first-letter|first-line|repeat-index|repeat-item|selection|value)"},t,{className:"attribute",begin:"\\b(src|z-index|word-wrap|word-spacing|word-break|width|widows|white-space|visibility|vertical-align|unicode-bidi|transition-timing-function|transition-property|transition-duration|transition-delay|transition|transform-style|transform-origin|transform|top|text-underline-position|text-transform|text-shadow|text-rendering|text-overflow|text-indent|text-decoration-style|text-decoration-line|text-decoration-color|text-decoration|text-align-last|text-align|tab-size|table-layout|right|resize|quotes|position|pointer-events|perspective-origin|perspective|page-break-inside|page-break-before|page-break-after|padding-top|padding-right|padding-left|padding-bottom|padding|overflow-y|overflow-x|overflow-wrap|overflow|outline-width|outline-style|outline-offset|outline-color|outline|orphans|order|opacity|object-position|object-fit|normal|none|nav-up|nav-right|nav-left|nav-index|nav-down|min-width|min-height|max-width|max-height|mask|marks|margin-top|margin-right|margin-left|margin-bottom|margin|list-style-type|list-style-position|list-style-image|list-style|line-height|letter-spacing|left|justify-content|initial|inherit|ime-mode|image-orientation|image-resolution|image-rendering|icon|hyphens|height|font-weight|font-variant-ligatures|font-variant|font-style|font-stretch|font-size-adjust|font-size|font-language-override|font-kerning|font-feature-settings|font-family|font|float|flex-wrap|flex-shrink|flex-grow|flex-flow|flex-direction|flex-basis|flex|filter|empty-cells|display|direction|cursor|counter-reset|counter-increment|content|column-width|column-span|column-rule-width|column-rule-style|column-rule-color|column-rule|column-gap|column-fill|column-count|columns|color|clip-path|clip|clear|caption-side|break-inside|break-before|break-after|box-sizing|box-shadow|box-decoration-break|bottom|border-width|border-top-width|border-top-style|border-top-right-radius|border-top-left-radius|border-top-color|border-top|border-style|border-spacing|border-right-width|border-right-style|border-right-color|border-right|border-radius|border-left-width|border-left-style|border-left-color|border-left|border-image-width|border-image-source|border-image-slice|border-image-repeat|border-image-outset|border-image|border-color|border-collapse|border-bottom-width|border-bottom-style|border-bottom-right-radius|border-bottom-left-radius|border-bottom-color|border-bottom|border|background-size|background-repeat|background-position|background-origin|background-image|background-color|background-clip|background-attachment|background-blend-mode|background|backface-visibility|auto|animation-timing-function|animation-play-state|animation-name|animation-iteration-count|animation-fill-mode|animation-duration|animation-direction|animation-delay|animation|align-self|align-items|align-content)\\b",illegal:"[^\\s]"},{begin:"\\b(whitespace|wait|w-resize|visible|vertical-text|vertical-ideographic|uppercase|upper-roman|upper-alpha|underline|transparent|top|thin|thick|text|text-top|text-bottom|tb-rl|table-header-group|table-footer-group|sw-resize|super|strict|static|square|solid|small-caps|separate|se-resize|scroll|s-resize|rtl|row-resize|ridge|right|repeat|repeat-y|repeat-x|relative|progress|pointer|overline|outside|outset|oblique|nowrap|not-allowed|normal|none|nw-resize|no-repeat|no-drop|newspaper|ne-resize|n-resize|move|middle|medium|ltr|lr-tb|lowercase|lower-roman|lower-alpha|loose|list-item|line|line-through|line-edge|lighter|left|keep-all|justify|italic|inter-word|inter-ideograph|inside|inset|inline|inline-block|inherit|inactive|ideograph-space|ideograph-parenthesis|ideograph-numeric|ideograph-alpha|horizontal|hidden|help|hand|groove|fixed|ellipsis|e-resize|double|dotted|distribute|distribute-space|distribute-letter|distribute-all-lines|disc|disabled|default|decimal|dashed|crosshair|collapse|col-resize|circle|char|center|capitalize|break-word|break-all|bottom|both|bolder|bold|block|bidi-override|below|baseline|auto|always|all-scroll|absolute|table|table-cell)\\b"},{begin:":",end:";",contains:[t,i,e.CSS_NUMBER_MODE,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,{className:"meta",begin:"!important"}]},{begin:"@(page|font-face)",lexemes:"@[a-z-]+",keywords:"@page @font-face"},{begin:"@",end:"[{;]",returnBegin:!0,keywords:"and or not only",contains:[{begin:"@[a-z-]+",className:"keyword"},t,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,i,e.CSS_NUMBER_MODE]}]}}}());hljs.registerLanguage("r",function(){"use strict";return function(e){var n="([a-zA-Z]|\\.[a-zA-Z.])[a-zA-Z0-9._]*";return{name:"R",contains:[e.HASH_COMMENT_MODE,{begin:n,keywords:{$pattern:n,keyword:"function if in break next repeat else for return switch while try tryCatch stop warning require library attach detach source setMethod setGeneric setGroupGeneric setClass ...",literal:"NULL NA TRUE FALSE T F Inf NaN NA_integer_|10 NA_real_|10 NA_character_|10 NA_complex_|10"},relevance:0},{className:"number",begin:"0[xX][0-9a-fA-F]+[Li]?\\b",relevance:0},{className:"number",begin:"\\d+(?:[eE][+\\-]?\\d*)?L\\b",relevance:0},{className:"number",begin:"\\d+\\.(?!\\d)(?:i\\b)?",relevance:0},{className:"number",begin:"\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b",relevance:0},{className:"number",begin:"\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b",relevance:0},{begin:"`",end:"`",relevance:0},{className:"string",contains:[e.BACKSLASH_ESCAPE],variants:[{begin:'"',end:'"'},{begin:"'",end:"'"}]}]}}}());hljs.registerLanguage("sql",function(){"use strict";return function(e){var t=e.COMMENT("--","$");return{name:"SQL",case_insensitive:!0,illegal:/[<>{}*]/,contains:[{beginKeywords:"begin end start commit rollback savepoint lock alter create drop rename call delete do handler insert load replace select truncate update set show pragma grant merge describe use explain help declare prepare execute deallocate release unlock purge reset change stop analyze cache flush optimize repair kill install uninstall checksum restore check backup revoke comment values with",end:/;/,endsWithParent:!0,keywords:{$pattern:/[\w\.]+/,keyword:"as abort abs absolute acc acce accep accept access accessed accessible account acos action activate add addtime admin administer advanced advise aes_decrypt aes_encrypt after agent aggregate ali alia alias all allocate allow alter always analyze ancillary and anti any anydata anydataset anyschema anytype apply archive archived archivelog are as asc ascii asin assembly assertion associate asynchronous at atan atn2 attr attri attrib attribu attribut attribute attributes audit authenticated authentication authid authors auto autoallocate autodblink autoextend automatic availability avg backup badfile basicfile before begin beginning benchmark between bfile bfile_base big bigfile bin binary_double binary_float binlog bit_and bit_count bit_length bit_or bit_xor bitmap blob_base block blocksize body both bound bucket buffer_cache buffer_pool build bulk by byte byteordermark bytes cache caching call calling cancel capacity cascade cascaded case cast catalog category ceil ceiling chain change changed char_base char_length character_length characters characterset charindex charset charsetform charsetid check checksum checksum_agg child choose chr chunk class cleanup clear client clob clob_base clone close cluster_id cluster_probability cluster_set clustering coalesce coercibility col collate collation collect colu colum column column_value columns columns_updated comment commit compact compatibility compiled complete composite_limit compound compress compute concat concat_ws concurrent confirm conn connec connect connect_by_iscycle connect_by_isleaf connect_by_root connect_time connection consider consistent constant constraint constraints constructor container content contents context contributors controlfile conv convert convert_tz corr corr_k corr_s corresponding corruption cos cost count count_big counted covar_pop covar_samp cpu_per_call cpu_per_session crc32 create creation critical cross cube cume_dist curdate current current_date current_time current_timestamp current_user cursor curtime customdatum cycle data database databases datafile datafiles datalength date_add date_cache date_format date_sub dateadd datediff datefromparts datename datepart datetime2fromparts day day_to_second dayname dayofmonth dayofweek dayofyear days db_role_change dbtimezone ddl deallocate declare decode decompose decrement decrypt deduplicate def defa defau defaul default defaults deferred defi defin define degrees delayed delegate delete delete_all delimited demand dense_rank depth dequeue des_decrypt des_encrypt des_key_file desc descr descri describ describe descriptor deterministic diagnostics difference dimension direct_load directory disable disable_all disallow disassociate discardfile disconnect diskgroup distinct distinctrow distribute distributed div do document domain dotnet double downgrade drop dumpfile duplicate duration each edition editionable editions element ellipsis else elsif elt empty enable enable_all enclosed encode encoding encrypt end end-exec endian enforced engine engines enqueue enterprise entityescaping eomonth error errors escaped evalname evaluate event eventdata events except exception exceptions exchange exclude excluding execu execut execute exempt exists exit exp expire explain explode export export_set extended extent external external_1 external_2 externally extract failed failed_login_attempts failover failure far fast feature_set feature_value fetch field fields file file_name_convert filesystem_like_logging final finish first first_value fixed flash_cache flashback floor flush following follows for forall force foreign form forma format found found_rows freelist freelists freepools fresh from from_base64 from_days ftp full function general generated get get_format get_lock getdate getutcdate global global_name globally go goto grant grants greatest group group_concat group_id grouping grouping_id groups gtid_subtract guarantee guard handler hash hashkeys having hea head headi headin heading heap help hex hierarchy high high_priority hosts hour hours http id ident_current ident_incr ident_seed identified identity idle_time if ifnull ignore iif ilike ilm immediate import in include including increment index indexes indexing indextype indicator indices inet6_aton inet6_ntoa inet_aton inet_ntoa infile initial initialized initially initrans inmemory inner innodb input insert install instance instantiable instr interface interleaved intersect into invalidate invisible is is_free_lock is_ipv4 is_ipv4_compat is_not is_not_null is_used_lock isdate isnull isolation iterate java join json json_exists keep keep_duplicates key keys kill language large last last_day last_insert_id last_value lateral lax lcase lead leading least leaves left len lenght length less level levels library like like2 like4 likec limit lines link list listagg little ln load load_file lob lobs local localtime localtimestamp locate locator lock locked log log10 log2 logfile logfiles logging logical logical_reads_per_call logoff logon logs long loop low low_priority lower lpad lrtrim ltrim main make_set makedate maketime managed management manual map mapping mask master master_pos_wait match matched materialized max maxextents maximize maxinstances maxlen maxlogfiles maxloghistory maxlogmembers maxsize maxtrans md5 measures median medium member memcompress memory merge microsecond mid migration min minextents minimum mining minus minute minutes minvalue missing mod mode model modification modify module monitoring month months mount move movement multiset mutex name name_const names nan national native natural nav nchar nclob nested never new newline next nextval no no_write_to_binlog noarchivelog noaudit nobadfile nocheck nocompress nocopy nocycle nodelay nodiscardfile noentityescaping noguarantee nokeep nologfile nomapping nomaxvalue nominimize nominvalue nomonitoring none noneditionable nonschema noorder nopr nopro noprom nopromp noprompt norely noresetlogs noreverse normal norowdependencies noschemacheck noswitch not nothing notice notnull notrim novalidate now nowait nth_value nullif nulls num numb numbe nvarchar nvarchar2 object ocicoll ocidate ocidatetime ociduration ociinterval ociloblocator ocinumber ociref ocirefcursor ocirowid ocistring ocitype oct octet_length of off offline offset oid oidindex old on online only opaque open operations operator optimal optimize option optionally or oracle oracle_date oradata ord ordaudio orddicom orddoc order ordimage ordinality ordvideo organization orlany orlvary out outer outfile outline output over overflow overriding package pad parallel parallel_enable parameters parent parse partial partition partitions pascal passing password password_grace_time password_lock_time password_reuse_max password_reuse_time password_verify_function patch path patindex pctincrease pctthreshold pctused pctversion percent percent_rank percentile_cont percentile_disc performance period period_add period_diff permanent physical pi pipe pipelined pivot pluggable plugin policy position post_transaction pow power pragma prebuilt precedes preceding precision prediction prediction_cost prediction_details prediction_probability prediction_set prepare present preserve prior priority private private_sga privileges procedural procedure procedure_analyze processlist profiles project prompt protection public publishingservername purge quarter query quick quiesce quota quotename radians raise rand range rank raw read reads readsize rebuild record records recover recovery recursive recycle redo reduced ref reference referenced references referencing refresh regexp_like register regr_avgx regr_avgy regr_count regr_intercept regr_r2 regr_slope regr_sxx regr_sxy reject rekey relational relative relaylog release release_lock relies_on relocate rely rem remainder rename repair repeat replace replicate replication required reset resetlogs resize resource respect restore restricted result result_cache resumable resume retention return returning returns reuse reverse revoke right rlike role roles rollback rolling rollup round row row_count rowdependencies rowid rownum rows rtrim rules safe salt sample save savepoint sb1 sb2 sb4 scan schema schemacheck scn scope scroll sdo_georaster sdo_topo_geometry search sec_to_time second seconds section securefile security seed segment select self semi sequence sequential serializable server servererror session session_user sessions_per_user set sets settings sha sha1 sha2 share shared shared_pool short show shrink shutdown si_averagecolor si_colorhistogram si_featurelist si_positionalcolor si_stillimage si_texture siblings sid sign sin size size_t sizes skip slave sleep smalldatetimefromparts smallfile snapshot some soname sort soundex source space sparse spfile split sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_small_result sql_variant_property sqlcode sqldata sqlerror sqlname sqlstate sqrt square standalone standby start starting startup statement static statistics stats_binomial_test stats_crosstab stats_ks_test stats_mode stats_mw_test stats_one_way_anova stats_t_test_ stats_t_test_indep stats_t_test_one stats_t_test_paired stats_wsr_test status std stddev stddev_pop stddev_samp stdev stop storage store stored str str_to_date straight_join strcmp strict string struct stuff style subdate subpartition subpartitions substitutable substr substring subtime subtring_index subtype success sum suspend switch switchoffset switchover sync synchronous synonym sys sys_xmlagg sysasm sysaux sysdate sysdatetimeoffset sysdba sysoper system system_user sysutcdatetime table tables tablespace tablesample tan tdo template temporary terminated tertiary_weights test than then thread through tier ties time time_format time_zone timediff timefromparts timeout timestamp timestampadd timestampdiff timezone_abbr timezone_minute timezone_region to to_base64 to_date to_days to_seconds todatetimeoffset trace tracking transaction transactional translate translation treat trigger trigger_nestlevel triggers trim truncate try_cast try_convert try_parse type ub1 ub2 ub4 ucase unarchived unbounded uncompress under undo unhex unicode uniform uninstall union unique unix_timestamp unknown unlimited unlock unnest unpivot unrecoverable unsafe unsigned until untrusted unusable unused update updated upgrade upped upper upsert url urowid usable usage use use_stored_outlines user user_data user_resources users using utc_date utc_timestamp uuid uuid_short validate validate_password_strength validation valist value values var var_samp varcharc vari varia variab variabl variable variables variance varp varraw varrawc varray verify version versions view virtual visible void wait wallet warning warnings week weekday weekofyear wellformed when whene whenev wheneve whenever where while whitespace window with within without work wrapped xdb xml xmlagg xmlattributes xmlcast xmlcolattval xmlelement xmlexists xmlforest xmlindex xmlnamespaces xmlpi xmlquery xmlroot xmlschema xmlserialize xmltable xmltype xor year year_to_month years yearweek",literal:"true false null unknown",built_in:"array bigint binary bit blob bool boolean char character date dec decimal float int int8 integer interval number numeric real record serial serial8 smallint text time timestamp tinyint varchar varchar2 varying void"},contains:[{className:"string",begin:"'",end:"'",contains:[{begin:"''"}]},{className:"string",begin:'"',end:'"',contains:[{begin:'""'}]},{className:"string",begin:"`",end:"`"},e.C_NUMBER_MODE,e.C_BLOCK_COMMENT_MODE,t,e.HASH_COMMENT_MODE]},e.C_BLOCK_COMMENT_MODE,t,e.HASH_COMMENT_MODE]}}}());hljs.registerLanguage("c",function(){"use strict";return function(e){var n=e.getLanguage("c-like").rawDefinition();return n.name="C",n.aliases=["c","h"],n}}());hljs.registerLanguage("json",function(){"use strict";return function(n){var e={literal:"true false null"},i=[n.C_LINE_COMMENT_MODE,n.C_BLOCK_COMMENT_MODE],t=[n.QUOTE_STRING_MODE,n.C_NUMBER_MODE],a={end:",",endsWithParent:!0,excludeEnd:!0,contains:t,keywords:e},l={begin:"{",end:"}",contains:[{className:"attr",begin:/"/,end:/"/,contains:[n.BACKSLASH_ESCAPE],illegal:"\\n"},n.inherit(a,{begin:/:/})].concat(i),illegal:"\\S"},s={begin:"\\[",end:"\\]",contains:[n.inherit(a)],illegal:"\\S"};return t.push(l,s),i.forEach((function(n){t.push(n)})),{name:"JSON",contains:t,keywords:e,illegal:"\\S"}}}());hljs.registerLanguage("python-repl",function(){"use strict";return function(n){return{aliases:["pycon"],contains:[{className:"meta",starts:{end:/ |$/,starts:{end:"$",subLanguage:"python"}},variants:[{begin:/^>>>(?=[ ]|$)/},{begin:/^\.\.\.(?=[ ]|$)/}]}]}}}());hljs.registerLanguage("markdown",function(){"use strict";return function(n){const e={begin:"<",end:">",subLanguage:"xml",relevance:0},a={begin:"\\[.+?\\][\\(\\[].*?[\\)\\]]",returnBegin:!0,contains:[{className:"string",begin:"\\[",end:"\\]",excludeBegin:!0,returnEnd:!0,relevance:0},{className:"link",begin:"\\]\\(",end:"\\)",excludeBegin:!0,excludeEnd:!0},{className:"symbol",begin:"\\]\\[",end:"\\]",excludeBegin:!0,excludeEnd:!0}],relevance:10},i={className:"strong",contains:[],variants:[{begin:/_{2}/,end:/_{2}/},{begin:/\*{2}/,end:/\*{2}/}]},s={className:"emphasis",contains:[],variants:[{begin:/\*(?!\*)/,end:/\*/},{begin:/_(?!_)/,end:/_/,relevance:0}]};i.contains.push(s),s.contains.push(i);var c=[e,a];return i.contains=i.contains.concat(c),s.contains=s.contains.concat(c),{name:"Markdown",aliases:["md","mkdown","mkd"],contains:[{className:"section",variants:[{begin:"^#{1,6}",end:"$",contains:c=c.concat(i,s)},{begin:"(?=^.+?\\n[=-]{2,}$)",contains:[{begin:"^[=-]*$"},{begin:"^",end:"\\n",contains:c}]}]},e,{className:"bullet",begin:"^[ \t]*([*+-]|(\\d+\\.))(?=\\s+)",end:"\\s+",excludeEnd:!0},i,s,{className:"quote",begin:"^>\\s+",contains:c,end:"$"},{className:"code",variants:[{begin:"(`{3,})(.|\\n)*?\\1`*[ ]*"},{begin:"(~{3,})(.|\\n)*?\\1~*[ ]*"},{begin:"```",end:"```+[ ]*$"},{begin:"~~~",end:"~~~+[ ]*$"},{begin:"`.+?`"},{begin:"(?=^( {4}|\\t))",contains:[{begin:"^( {4}|\\t)",end:"(\\n)$"}],relevance:0}]},{begin:"^[-\\*]{3,}",end:"$"},a,{begin:/^\[[^\n]+\]:/,returnBegin:!0,contains:[{className:"symbol",begin:/\[/,end:/\]/,excludeBegin:!0,excludeEnd:!0},{className:"link",begin:/:\s*/,end:/$/,excludeBegin:!0}]}]}}}());hljs.registerLanguage("javascript",function(){"use strict";const e=["as","in","of","if","for","while","finally","var","new","function","do","return","void","else","break","catch","instanceof","with","throw","case","default","try","switch","continue","typeof","delete","let","yield","const","class","debugger","async","await","static","import","from","export","extends"],n=["true","false","null","undefined","NaN","Infinity"],a=[].concat(["setInterval","setTimeout","clearInterval","clearTimeout","require","exports","eval","isFinite","isNaN","parseFloat","parseInt","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape"],["arguments","this","super","console","window","document","localStorage","module","global"],["Intl","DataView","Number","Math","Date","String","RegExp","Object","Function","Boolean","Error","Symbol","Set","Map","WeakSet","WeakMap","Proxy","Reflect","JSON","Promise","Float64Array","Int16Array","Int32Array","Int8Array","Uint16Array","Uint32Array","Float32Array","Array","Uint8Array","Uint8ClampedArray","ArrayBuffer"],["EvalError","InternalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError"]);function s(e){return r("(?=",e,")")}function r(...e){return e.map(e=>(function(e){return e?"string"==typeof e?e:e.source:null})(e)).join("")}return function(t){var i="[A-Za-z$_][0-9A-Za-z$_]*",c={begin:/<[A-Za-z0-9\\._:-]+/,end:/\/[A-Za-z0-9\\._:-]+>|\/>/},o={$pattern:"[A-Za-z$_][0-9A-Za-z$_]*",keyword:e.join(" "),literal:n.join(" "),built_in:a.join(" ")},l={className:"number",variants:[{begin:"\\b(0[bB][01]+)n?"},{begin:"\\b(0[oO][0-7]+)n?"},{begin:t.C_NUMBER_RE+"n?"}],relevance:0},E={className:"subst",begin:"\\$\\{",end:"\\}",keywords:o,contains:[]},d={begin:"html`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,E],subLanguage:"xml"}},g={begin:"css`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,E],subLanguage:"css"}},u={className:"string",begin:"`",end:"`",contains:[t.BACKSLASH_ESCAPE,E]};E.contains=[t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,d,g,u,l,t.REGEXP_MODE];var b=E.contains.concat([{begin:/\(/,end:/\)/,contains:["self"].concat(E.contains,[t.C_BLOCK_COMMENT_MODE,t.C_LINE_COMMENT_MODE])},t.C_BLOCK_COMMENT_MODE,t.C_LINE_COMMENT_MODE]),_={className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,contains:b};return{name:"JavaScript",aliases:["js","jsx","mjs","cjs"],keywords:o,contains:[t.SHEBANG({binary:"node",relevance:5}),{className:"meta",relevance:10,begin:/^\s*['"]use (strict|asm)['"]/},t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,d,g,u,t.C_LINE_COMMENT_MODE,t.COMMENT("/\\*\\*","\\*/",{relevance:0,contains:[{className:"doctag",begin:"@[A-Za-z]+",contains:[{className:"type",begin:"\\{",end:"\\}",relevance:0},{className:"variable",begin:i+"(?=\\s*(-)|$)",endsParent:!0,relevance:0},{begin:/(?=[^\n])\s/,relevance:0}]}]}),t.C_BLOCK_COMMENT_MODE,l,{begin:r(/[{,\n]\s*/,s(r(/(((\/\/.*)|(\/\*(.|\n)*\*\/))\s*)*/,i+"\\s*:"))),relevance:0,contains:[{className:"attr",begin:i+s("\\s*:"),relevance:0}]},{begin:"("+t.RE_STARTERS_RE+"|\\b(case|return|throw)\\b)\\s*",keywords:"return throw case",contains:[t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,t.REGEXP_MODE,{className:"function",begin:"(\\([^(]*(\\([^(]*(\\([^(]*\\))?\\))?\\)|"+t.UNDERSCORE_IDENT_RE+")\\s*=>",returnBegin:!0,end:"\\s*=>",contains:[{className:"params",variants:[{begin:t.UNDERSCORE_IDENT_RE},{className:null,begin:/\(\s*\)/,skip:!0},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:o,contains:b}]}]},{begin:/,/,relevance:0},{className:"",begin:/\s/,end:/\s*/,skip:!0},{variants:[{begin:"<>",end:""},{begin:c.begin,end:c.end}],subLanguage:"xml",contains:[{begin:c.begin,end:c.end,skip:!0,contains:["self"]}]}],relevance:0},{className:"function",beginKeywords:"function",end:/\{/,excludeEnd:!0,contains:[t.inherit(t.TITLE_MODE,{begin:i}),_],illegal:/\[|%/},{begin:/\$[(.]/},t.METHOD_GUARD,{className:"class",beginKeywords:"class",end:/[{;=]/,excludeEnd:!0,illegal:/[:"\[\]]/,contains:[{beginKeywords:"extends"},t.UNDERSCORE_TITLE_MODE]},{beginKeywords:"constructor",end:/\{/,excludeEnd:!0},{begin:"(get|set)\\s+(?="+i+"\\()",end:/{/,keywords:"get set",contains:[t.inherit(t.TITLE_MODE,{begin:i}),{begin:/\(\)/},_]}],illegal:/#(?!!)/}}}());hljs.registerLanguage("typescript",function(){"use strict";const e=["as","in","of","if","for","while","finally","var","new","function","do","return","void","else","break","catch","instanceof","with","throw","case","default","try","switch","continue","typeof","delete","let","yield","const","class","debugger","async","await","static","import","from","export","extends"],n=["true","false","null","undefined","NaN","Infinity"],a=[].concat(["setInterval","setTimeout","clearInterval","clearTimeout","require","exports","eval","isFinite","isNaN","parseFloat","parseInt","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape"],["arguments","this","super","console","window","document","localStorage","module","global"],["Intl","DataView","Number","Math","Date","String","RegExp","Object","Function","Boolean","Error","Symbol","Set","Map","WeakSet","WeakMap","Proxy","Reflect","JSON","Promise","Float64Array","Int16Array","Int32Array","Int8Array","Uint16Array","Uint32Array","Float32Array","Array","Uint8Array","Uint8ClampedArray","ArrayBuffer"],["EvalError","InternalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError"]);return function(r){var t={$pattern:"[A-Za-z$_][0-9A-Za-z$_]*",keyword:e.concat(["type","namespace","typedef","interface","public","private","protected","implements","declare","abstract","readonly"]).join(" "),literal:n.join(" "),built_in:a.concat(["any","void","number","boolean","string","object","never","enum"]).join(" ")},s={className:"meta",begin:"@[A-Za-z$_][0-9A-Za-z$_]*"},i={className:"number",variants:[{begin:"\\b(0[bB][01]+)n?"},{begin:"\\b(0[oO][0-7]+)n?"},{begin:r.C_NUMBER_RE+"n?"}],relevance:0},o={className:"subst",begin:"\\$\\{",end:"\\}",keywords:t,contains:[]},c={begin:"html`",end:"",starts:{end:"`",returnEnd:!1,contains:[r.BACKSLASH_ESCAPE,o],subLanguage:"xml"}},l={begin:"css`",end:"",starts:{end:"`",returnEnd:!1,contains:[r.BACKSLASH_ESCAPE,o],subLanguage:"css"}},E={className:"string",begin:"`",end:"`",contains:[r.BACKSLASH_ESCAPE,o]};o.contains=[r.APOS_STRING_MODE,r.QUOTE_STRING_MODE,c,l,E,i,r.REGEXP_MODE];var d={begin:"\\(",end:/\)/,keywords:t,contains:["self",r.QUOTE_STRING_MODE,r.APOS_STRING_MODE,r.NUMBER_MODE]},u={className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:t,contains:[r.C_LINE_COMMENT_MODE,r.C_BLOCK_COMMENT_MODE,s,d]};return{name:"TypeScript",aliases:["ts"],keywords:t,contains:[r.SHEBANG(),{className:"meta",begin:/^\s*['"]use strict['"]/},r.APOS_STRING_MODE,r.QUOTE_STRING_MODE,c,l,E,r.C_LINE_COMMENT_MODE,r.C_BLOCK_COMMENT_MODE,i,{begin:"("+r.RE_STARTERS_RE+"|\\b(case|return|throw)\\b)\\s*",keywords:"return throw case",contains:[r.C_LINE_COMMENT_MODE,r.C_BLOCK_COMMENT_MODE,r.REGEXP_MODE,{className:"function",begin:"(\\([^(]*(\\([^(]*(\\([^(]*\\))?\\))?\\)|"+r.UNDERSCORE_IDENT_RE+")\\s*=>",returnBegin:!0,end:"\\s*=>",contains:[{className:"params",variants:[{begin:r.UNDERSCORE_IDENT_RE},{className:null,begin:/\(\s*\)/,skip:!0},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:t,contains:d.contains}]}]}],relevance:0},{className:"function",beginKeywords:"function",end:/[\{;]/,excludeEnd:!0,keywords:t,contains:["self",r.inherit(r.TITLE_MODE,{begin:"[A-Za-z$_][0-9A-Za-z$_]*"}),u],illegal:/%/,relevance:0},{beginKeywords:"constructor",end:/[\{;]/,excludeEnd:!0,contains:["self",u]},{begin:/module\./,keywords:{built_in:"module"},relevance:0},{beginKeywords:"module",end:/\{/,excludeEnd:!0},{beginKeywords:"interface",end:/\{/,excludeEnd:!0,keywords:"interface extends"},{begin:/\$[(.]/},{begin:"\\."+r.IDENT_RE,relevance:0},s,d]}}}());hljs.registerLanguage("plaintext",function(){"use strict";return function(t){return{name:"Plain text",aliases:["text","txt"],disableAutodetect:!0}}}());hljs.registerLanguage("less",function(){"use strict";return function(e){var n="([\\w-]+|@{[\\w-]+})",a=[],s=[],t=function(e){return{className:"string",begin:"~?"+e+".*?"+e}},r=function(e,n,a){return{className:e,begin:n,relevance:a}},i={begin:"\\(",end:"\\)",contains:s,relevance:0};s.push(e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,t("'"),t('"'),e.CSS_NUMBER_MODE,{begin:"(url|data-uri)\\(",starts:{className:"string",end:"[\\)\\n]",excludeEnd:!0}},r("number","#[0-9A-Fa-f]+\\b"),i,r("variable","@@?[\\w-]+",10),r("variable","@{[\\w-]+}"),r("built_in","~?`[^`]*?`"),{className:"attribute",begin:"[\\w-]+\\s*:",end:":",returnBegin:!0,excludeEnd:!0},{className:"meta",begin:"!important"});var c=s.concat({begin:"{",end:"}",contains:a}),l={beginKeywords:"when",endsWithParent:!0,contains:[{beginKeywords:"and not"}].concat(s)},o={begin:n+"\\s*:",returnBegin:!0,end:"[;}]",relevance:0,contains:[{className:"attribute",begin:n,end:":",excludeEnd:!0,starts:{endsWithParent:!0,illegal:"[<=$]",relevance:0,contains:s}}]},g={className:"keyword",begin:"@(import|media|charset|font-face|(-[a-z]+-)?keyframes|supports|document|namespace|page|viewport|host)\\b",starts:{end:"[;{}]",returnEnd:!0,contains:s,relevance:0}},d={className:"variable",variants:[{begin:"@[\\w-]+\\s*:",relevance:15},{begin:"@[\\w-]+"}],starts:{end:"[;}]",returnEnd:!0,contains:c}},b={variants:[{begin:"[\\.#:&\\[>]",end:"[;{}]"},{begin:n,end:"{"}],returnBegin:!0,returnEnd:!0,illegal:"[<='$\"]",relevance:0,contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,l,r("keyword","all\\b"),r("variable","@{[\\w-]+}"),r("selector-tag",n+"%?",0),r("selector-id","#"+n),r("selector-class","\\."+n,0),r("selector-tag","&",0),{className:"selector-attr",begin:"\\[",end:"\\]"},{className:"selector-pseudo",begin:/:(:)?[a-zA-Z0-9\_\-\+\(\)"'.]+/},{begin:"\\(",end:"\\)",contains:c},{begin:"!important"}]};return a.push(e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,g,d,o,b),{name:"Less",case_insensitive:!0,illegal:"[=>'/<($\"]",contains:a}}}());hljs.registerLanguage("lua",function(){"use strict";return function(e){var t={begin:"\\[=*\\[",end:"\\]=*\\]",contains:["self"]},a=[e.COMMENT("--(?!\\[=*\\[)","$"),e.COMMENT("--\\[=*\\[","\\]=*\\]",{contains:[t],relevance:10})];return{name:"Lua",keywords:{$pattern:e.UNDERSCORE_IDENT_RE,literal:"true false nil",keyword:"and break do else elseif end for goto if in local not or repeat return then until while",built_in:"_G _ENV _VERSION __index __newindex __mode __call __metatable __tostring __len __gc __add __sub __mul __div __mod __pow __concat __unm __eq __lt __le assert collectgarbage dofile error getfenv getmetatable ipairs load loadfile loadstring module next pairs pcall print rawequal rawget rawset require select setfenv setmetatable tonumber tostring type unpack xpcall arg self coroutine resume yield status wrap create running debug getupvalue debug sethook getmetatable gethook setmetatable setlocal traceback setfenv getinfo setupvalue getlocal getregistry getfenv io lines write close flush open output type read stderr stdin input stdout popen tmpfile math log max acos huge ldexp pi cos tanh pow deg tan cosh sinh random randomseed frexp ceil floor rad abs sqrt modf asin min mod fmod log10 atan2 exp sin atan os exit setlocale date getenv difftime remove time clock tmpname rename execute package preload loadlib loaded loaders cpath config path seeall string sub upper len gfind rep find match char dump gmatch reverse byte format gsub lower table setn insert getn foreachi maxn foreach concat sort remove"},contains:a.concat([{className:"function",beginKeywords:"function",end:"\\)",contains:[e.inherit(e.TITLE_MODE,{begin:"([_a-zA-Z]\\w*\\.)*([_a-zA-Z]\\w*:)?[_a-zA-Z]\\w*"}),{className:"params",begin:"\\(",endsWithParent:!0,contains:a}].concat(a)},e.C_NUMBER_MODE,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,{className:"string",begin:"\\[=*\\[",end:"\\]=*\\]",contains:[t],relevance:5}])}}}()); diff --git a/hir-debugging.html b/hir-debugging.html new file mode 100644 index 000000000..2f08d1930 --- /dev/null +++ b/hir-debugging.html @@ -0,0 +1,214 @@ + + + + + + Debugging - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

HIR Debugging

+

Use the -Z unpretty=hir flag to produce a human-readable representation of the HIR. +For cargo projects this can be done with cargo rustc -- -Z unpretty=hir. +This output is useful when you need to see at a glance how your code was desugared and transformed +during AST lowering.

+

For a full Debug dump of the data in the HIR, use the -Z unpretty=hir-tree flag. +This may be useful when you need to see the full structure of the HIR from the perspective of the +compiler.

+

If you are trying to correlate NodeIds or DefIds with source code, the +-Z unpretty=expanded,identified flag may be useful.

+

TODO: anything else? #1159

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/hir.html b/hir.html new file mode 100644 index 000000000..6d4059bbd --- /dev/null +++ b/hir.html @@ -0,0 +1,299 @@ + + + + + + The HIR (High-level IR) - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

The HIR

+ +

The HIR – "High-Level Intermediate Representation" – is the primary IR used +in most of rustc. It is a compiler-friendly representation of the abstract +syntax tree (AST) that is generated after parsing, macro expansion, and name +resolution (see Lowering for how the HIR is created). +Many parts of HIR resemble Rust surface syntax quite closely, with +the exception that some of Rust's expression forms have been desugared away. +For example, for loops are converted into a loop and do not appear in +the HIR. This makes HIR more amenable to analysis than a normal AST.

+

This chapter covers the main concepts of the HIR.

+

You can view the HIR representation of your code by passing the +-Z unpretty=hir-tree flag to rustc:

+
cargo rustc -- -Z unpretty=hir-tree
+
+

You can also use the -Z unpretty=hir option to generate a HIR +that is closer to the original source code expression:

+
cargo rustc -- -Z unpretty=hir
+
+

Out-of-band storage and the Crate type

+

The top-level data-structure in the HIR is the Crate, which stores +the contents of the crate currently being compiled (we only ever +construct HIR for the current crate). Whereas in the AST the crate +data structure basically just contains the root module, the HIR +Crate structure contains a number of maps and other things that +serve to organize the content of the crate for easier access.

+

For example, the contents of individual items (e.g. modules, +functions, traits, impls, etc) in the HIR are not immediately +accessible in the parents. So, for example, if there is a module item +foo containing a function bar():

+
#![allow(unused)]
+fn main() {
+mod foo {
+    fn bar() { }
+}
+}
+
+

then in the HIR the representation of module foo (the Mod +struct) would only have the ItemId I of bar(). To get the +details of the function bar(), we would lookup I in the +items map.

+

One nice result from this representation is that one can iterate +over all items in the crate by iterating over the key-value pairs +in these maps (without the need to trawl through the whole HIR). +There are similar maps for things like trait items and impl items, +as well as "bodies" (explained below).

+

The other reason to set up the representation this way is for better +integration with incremental compilation. This way, if you gain access +to an &rustc_hir::Item (e.g. for the mod foo), you do not immediately +gain access to the contents of the function bar(). Instead, you only +gain access to the id for bar(), and you must invoke some +function to lookup the contents of bar() given its id; this gives +the compiler a chance to observe that you accessed the data for +bar(), and then record the dependency.

+

+

Identifiers in the HIR

+

There are a bunch of different identifiers to refer to other nodes or definitions +in the HIR. In short:

+
    +
  • A DefId refers to a definition in any crate.
  • +
  • A LocalDefId refers to a definition in the currently compiled crate.
  • +
  • A HirId refers to any node in the HIR.
  • +
+

For more detailed information, check out the chapter on identifiers.

+

The HIR Map

+

Most of the time when you are working with the HIR, you will do so via +the HIR Map, accessible in the tcx via tcx.hir() (and defined in +the hir::map module). The HIR map contains a number of methods to +convert between IDs of various kinds and to lookup data associated +with a HIR node.

+

For example, if you have a LocalDefId, and you would like to convert it +to a HirId, you can use tcx.hir().local_def_id_to_hir_id(def_id). +You need a LocalDefId, rather than a DefId, since only local items have HIR nodes.

+

Similarly, you can use tcx.hir().find(n) to lookup the node for a +HirId. This returns a Option<Node<'hir>>, where Node is an enum +defined in the map. By matching on this, you can find out what sort of +node the HirId referred to and also get a pointer to the data +itself. Often, you know what sort of node n is – e.g. if you know +that n must be some HIR expression, you can do +tcx.hir().expect_expr(n), which will extract and return the +&hir::Expr, panicking if n is not in fact an expression.

+

Finally, you can use the HIR map to find the parents of nodes, via +calls like tcx.hir().get_parent(n).

+

HIR Bodies

+

A rustc_hir::Body represents some kind of executable code, such as the body +of a function/closure or the definition of a constant. Bodies are +associated with an owner, which is typically some kind of item +(e.g. an fn() or const), but could also be a closure expression +(e.g. |x, y| x + y). You can use the HIR map to find the body +associated with a given def-id (maybe_body_owned_by) or to find +the owner of a body (body_owner_def_id).

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/identifiers.html b/identifiers.html new file mode 100644 index 000000000..b3f79a7eb --- /dev/null +++ b/identifiers.html @@ -0,0 +1,286 @@ + + + + + + Identifiers in the Compiler - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Identifiers in the compiler

+

If you have read the few previous chapters, you now know that rustc uses +many different intermediate representations to perform different kinds of analyses. +However, like in every data structure, you need a way to traverse the structure +and refer to other elements. In this chapter, you will find information on the +different identifiers rustc uses for each intermediate representation.

+

In the AST

+

A NodeId is an identifier number that uniquely identifies an AST node within +a crate. Every node in the AST has its own NodeId, including top-level items +such as structs, but also individual statements and expressions.

+

However, because they are absolute within a crate, adding or removing a single +node in the AST causes all the subsequent NodeIds to change. This renders +NodeIds pretty much useless for incremental compilation, where you want as +few things as possible to change.

+

NodeIds are used in all the rustc bits that operate directly on the AST, +like macro expansion and name resolution.

+

In the HIR

+

The HIR uses a bunch of different identifiers that coexist and serve different purposes.

+
    +
  • +

    A DefId, as the name suggests, identifies a particular definition, or top-level +item, in a given crate. It is composed of two parts: a CrateNum which identifies +the crate the definition comes from, and a DefIndex which identifies the definition +within the crate. Unlike HirIds, there isn't a DefId for every expression, which +makes them more stable across compilations.

    +
  • +
  • +

    A LocalDefId is basically a DefId that is known to come from the current crate. +This allows us to drop the CrateNum part, and use the type system to ensure that +only local definitions are passed to functions that expect a local definition.

    +
  • +
  • +

    A HirId uniquely identifies a node in the HIR of the current crate. It is composed +of two parts: an owner and a local_id that is unique within the owner. This +combination makes for more stable values which are helpful for incremental compilation. +Unlike DefIds, a HirId can refer to fine-grained entities like expressions, +but stays local to the current crate.

    +
  • +
  • +

    A BodyId identifies a HIR Body in the current crate. It is currently only +a wrapper around a HirId. For more info about HIR bodies, please refer to the +HIR chapter.

    +
  • +
+

These identifiers can be converted into one another through the HIR map. +See the HIR chapter for more detailed information.

+

In the MIR

+
    +
  • +

    BasicBlock identifies a basic block. It points to an instance of +BasicBlockData, which can be retrieved by indexing into +Body.basic_blocks.

    +
  • +
  • +

    Local identifies a local variable in a function. Its associated data is in +LocalDecl, which can be retrieved by indexing into Body.local_decls.

    +
  • +
  • +

    FieldIdx identifies a struct's, union's, or enum variant's field. It is used +as a "projection" in Place.

    +
  • +
  • +

    SourceScope identifies a name scope in the original source code. Used for +diagnostics and for debuginfo in debuggers. It points to an instance of +SourceScopeData, which can be retrieved by indexing into +Body.source_scopes.

    +
  • +
  • +

    Promoted identifies a promoted constant within another item (related to +const evaluation). Note: it is unique only locally within the item, so it +should be associated with a DefId. +GlobalId will give you a more specific identifier.

    +
  • +
  • +

    GlobalId identifies a global variable: a const, a static, a const fn +where all arguments are zero-sized types, or a promoted constant.

    +
  • +
  • +

    Location represents the location in the MIR of a statement or terminator. +It identifies the block (using BasicBlock) and the index of the statement +or terminator in the block.

    +
  • +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/img/coverage-branch-counting-01.png b/img/coverage-branch-counting-01.png new file mode 100644 index 000000000..c445f3552 Binary files /dev/null and b/img/coverage-branch-counting-01.png differ diff --git a/img/dataflow-graphviz-example.png b/img/dataflow-graphviz-example.png new file mode 100644 index 000000000..718411a8c Binary files /dev/null and b/img/dataflow-graphviz-example.png differ diff --git a/img/github-cli.png b/img/github-cli.png new file mode 100644 index 000000000..c3b0e7707 Binary files /dev/null and b/img/github-cli.png differ diff --git a/img/github-whitespace-changes.png b/img/github-whitespace-changes.png new file mode 100644 index 000000000..9a19a10aa Binary files /dev/null and b/img/github-whitespace-changes.png differ diff --git a/img/llvm-cov-show-01.png b/img/llvm-cov-show-01.png new file mode 100644 index 000000000..35f045943 Binary files /dev/null and b/img/llvm-cov-show-01.png differ diff --git a/img/other-peoples-commits.png b/img/other-peoples-commits.png new file mode 100644 index 000000000..e4fc2c797 Binary files /dev/null and b/img/other-peoples-commits.png differ diff --git a/img/rustbot-submodules.png b/img/rustbot-submodules.png new file mode 100644 index 000000000..c2e6937cb Binary files /dev/null and b/img/rustbot-submodules.png differ diff --git a/img/submodule-conflicts.png b/img/submodule-conflicts.png new file mode 100644 index 000000000..e90a6bbe8 Binary files /dev/null and b/img/submodule-conflicts.png differ diff --git a/img/wpa-initial-memory.png b/img/wpa-initial-memory.png new file mode 100644 index 000000000..b6020667e Binary files /dev/null and b/img/wpa-initial-memory.png differ diff --git a/img/wpa-stack.png b/img/wpa-stack.png new file mode 100644 index 000000000..29eb5a54b Binary files /dev/null and b/img/wpa-stack.png differ diff --git a/implementing_new_features.html b/implementing_new_features.html new file mode 100644 index 000000000..57f2cbb45 --- /dev/null +++ b/implementing_new_features.html @@ -0,0 +1,370 @@ + + + + + + Implementing new language features - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Implementing new language features

+ +

When you want to implement a new significant feature in the compiler, +you need to go through this process to make sure everything goes +smoothly.

+

NOTE: this section is for language features, not library features, +which use a different process.

+

The @rfcbot FCP process

+

When the change is small and uncontroversial, then it can be done +with just writing a PR and getting an r+ from someone who knows that +part of the code. However, if the change is potentially controversial, +it would be a bad idea to push it without consensus from the rest +of the team (both in the "distributed system" sense to make sure +you don't break anything you don't know about, and in the social +sense to avoid PR fights).

+

If such a change seems to be too small to require a full formal RFC process +(e.g., a small standard library addition, a big refactoring of the code, a +"technically-breaking" change, or a "big bugfix" that basically amounts to a +small feature) but is still too controversial or big to get by with a single r+, +you can propose a final comment period (FCP). Or, if you're not on the relevant +team (and thus don't have @rfcbot permissions), ask someone who is to start one; +unless they have a concern themselves, they should.

+

Again, the FCP process is only needed if you need consensus – if you +don't think anyone would have a problem with your change, it's OK to +get by with only an r+. For example, it is OK to add or modify +unstable command-line flags or attributes without an FCP for +compiler development or standard library use, as long as you don't +expect them to be in wide use in the nightly ecosystem. +Some teams have lighter weight processes that they use in scenarios +like this; for example, the compiler team recommends +filing a Major Change Proposal (MCP) as a lightweight way to +garner support and feedback without requiring full consensus.

+

You don't need to have the implementation fully ready for r+ to propose an FCP, +but it is generally a good idea to have at least a proof +of concept so that people can see what you are talking about.

+

When an FCP is proposed, it requires all members of the team to sign off the +FCP. After they all do so, there's a 10-day-long "final comment period" (hence +the name) where everybody can comment, and if no concerns are raised, the +PR/issue gets FCP approval.

+

The logistics of writing features

+

There are a few "logistic" hoops you might need to go through in +order to implement a feature in a working way.

+

Warning Cycles

+

In some cases, a feature or bugfix might break some existing programs +in some edge cases. In that case, you might want to do a crater run +to assess the impact and possibly add a future-compatibility lint, +similar to those used for +edition-gated lints.

+

Stability

+

We value the stability of Rust. Code that works and runs on stable +should (mostly) not break. Because of that, we don't want to release +a feature to the world with only team consensus and code review - +we want to gain real-world experience on using that feature on nightly, +and we might want to change the feature based on that experience.

+

To allow for that, we must make sure users don't accidentally depend +on that new feature - otherwise, especially if experimentation takes +time or is delayed and the feature takes the trains to stable, +it would end up de facto stable and we'll not be able to make changes +in it without breaking people's code.

+

The way we do that is that we make sure all new features are feature +gated - they can't be used without enabling a feature gate +(#[feature(foo)]), which can't be done in a stable/beta compiler. +See the stability in code section for the technical details.

+

Eventually, after we gain enough experience using the feature, +make the necessary changes, and are satisfied, we expose it to +the world using the stabilization process described here. +Until then, the feature is not set in stone: every part of the +feature can be changed, or the feature might be completely +rewritten or removed. Features are not supposed to gain tenure +by being unstable and unchanged for a year.

+

Tracking Issues

+

To keep track of the status of an unstable feature, the +experience we get while using it on nightly, and of the +concerns that block its stabilization, every feature-gate +needs a tracking issue. General discussions about the feature should be done on the tracking issue.

+

For features that have an RFC, you should use the RFC's +tracking issue for the feature.

+

For other features, you'll have to make a tracking issue +for that feature. The issue title should be "Tracking issue +for YOUR FEATURE". Use the "Tracking Issue" issue template.

+

Stability in code

+

The below steps needs to be followed in order to implement +a new unstable feature:

+
    +
  1. +

    Open a tracking issue - +if you have an RFC, you can use the tracking issue for the RFC.

    +

    The tracking issue should be labeled with at least C-tracking-issue. +For a language feature, a label F-feature_name should be added as well.

    +
  2. +
  3. +

    Pick a name for the feature gate (for RFCs, use the name +in the RFC).

    +
  4. +
  5. +

    Add the feature name to rustc_span/src/symbol.rs in the Symbols {...} block.

    +

    Note that this block must be in alphabetical order.

    +
  6. +
  7. +

    Add a feature gate declaration to rustc_feature/src/unstable.rs in the unstable +declare_features block.

    +
    /// description of feature
    +(unstable, $feature_name, "CURRENT_RUSTC_VERSION", Some($tracking_issue_number))
    +
    +

    If you haven't yet +opened a tracking issue (e.g. because you want initial feedback on whether the feature is likely +to be accepted), you can temporarily use None - but make sure to update it before the PR is +merged!

    +

    For example:

    +
    /// Allows defining identifiers beyond ASCII.
    +(unstable, non_ascii_idents, "CURRENT_RUSTC_VERSION", Some(55467), None),
    +
    +

    Features can be marked as incomplete, and trigger the warn-by-default incomplete_features +lint +by setting their type to incomplete:

    +
    /// Allows unsized rvalues at arguments and parameters.
    +(incomplete, unsized_locals, "CURRENT_RUSTC_VERSION", Some(48055), None),
    +
    +

    To avoid semantic merge conflicts, please use CURRENT_RUSTC_VERSION instead of 1.70 or +another explicit version number.

    +
  8. +
  9. +

    Prevent usage of the new feature unless the feature gate is set. +You can check it in most places in the compiler using the +expression tcx.features().$feature_name (or +sess.features_untracked().$feature_name if the +tcx is unavailable)

    +

    If the feature gate is not set, you should either maintain +the pre-feature behavior or raise an error, depending on +what makes sense. Errors should generally use rustc_session::parse::feature_err. +For an example of adding an error, see #81015.

    +

    For features introducing new syntax, pre-expansion gating should be used instead. +During parsing, when the new syntax is parsed, the symbol must be inserted to the +current crate's GatedSpans via self.sess.gated_span.gate(sym::my_feature, span).

    +

    After being inserted to the gated spans, the span must be checked in the +rustc_ast_passes::feature_gate::check_crate function, which actually denies +features. Exactly how it is gated depends on the exact type of feature, but most +likely will use the gate_all!() macro.

    +
  10. +
  11. +

    Add a test to ensure the feature cannot be used without +a feature gate, by creating tests/ui/feature-gates/feature-gate-$feature_name.rs. +You can generate the corresponding .stderr file by running ./x test tests/ui/feature-gates/ --bless.

    +
  12. +
  13. +

    Add a section to the unstable book, in +src/doc/unstable-book/src/language-features/$feature_name.md.

    +
  14. +
  15. +

    Write a lot of tests for the new feature, preferably in tests/ui/$feature_name/. +PRs without tests will not be accepted!

    +
  16. +
  17. +

    Get your PR reviewed and land it. You have now successfully +implemented a feature in Rust!

    +
  18. +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/incrcomp-debugging.html b/incrcomp-debugging.html new file mode 100644 index 000000000..bdee661f6 --- /dev/null +++ b/incrcomp-debugging.html @@ -0,0 +1,296 @@ + + + + + + Debugging and Testing - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Debugging and Testing Dependencies

+

Testing the dependency graph

+

There are various ways to write tests against the dependency graph. The +simplest mechanisms are the #[rustc_if_this_changed] and +#[rustc_then_this_would_need] annotations. These are used in ui tests to test +whether the expected set of paths exist in the dependency graph.

+

As an example, see tests/ui/dep-graph/dep-graph-caller-callee.rs, or the +tests below.

+
#[rustc_if_this_changed]
+fn foo() { }
+
+#[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK
+fn bar() { foo(); }
+
+

This should be read as

+
+

If this (foo) is changed, then this (i.e. bar)'s TypeckTables would need to be changed.

+
+

Technically, what occurs is that the test is expected to emit the string "OK" on +stderr, associated to this line.

+

You could also add the lines

+
#[rustc_then_this_would_need(TypeckTables)] //~ ERROR no path
+fn baz() { }
+
+

Whose meaning is

+
+

If foo is changed, then baz's TypeckTables does not need to be changed. +The macro must emit an error, and the error message must contains "no path".

+
+

Recall that the //~ ERROR OK is a comment from the point of view of the Rust +code we test, but is meaningful from the point of view of the test itself.

+

Debugging the dependency graph

+

Dumping the graph

+

The compiler is also capable of dumping the dependency graph for your +debugging pleasure. To do so, pass the -Z dump-dep-graph flag. The +graph will be dumped to dep_graph.{txt,dot} in the current +directory. You can override the filename with the RUST_DEP_GRAPH +environment variable.

+

Frequently, though, the full dep graph is quite overwhelming and not +particularly helpful. Therefore, the compiler also allows you to filter +the graph. You can filter in three ways:

+
    +
  1. All edges originating in a particular set of nodes (usually a single node).
  2. +
  3. All edges reaching a particular set of nodes.
  4. +
  5. All edges that lie between given start and end nodes.
  6. +
+

To filter, use the RUST_DEP_GRAPH_FILTER environment variable, which should +look like one of the following:

+
source_filter     // nodes originating from source_filter
+-> target_filter  // nodes that can reach target_filter
+source_filter -> target_filter // nodes in between source_filter and target_filter
+
+

source_filter and target_filter are a &-separated list of strings. +A node is considered to match a filter if all of those strings appear in its +label. So, for example:

+
RUST_DEP_GRAPH_FILTER='-> TypeckTables'
+
+

would select the predecessors of all TypeckTables nodes. Usually though you +want the TypeckTables node for some particular fn, so you might write:

+
RUST_DEP_GRAPH_FILTER='-> TypeckTables & bar'
+
+

This will select only the predecessors of TypeckTables nodes for functions +with bar in their name.

+

Perhaps you are finding that when you change foo you need to re-type-check +bar, but you don't think you should have to. In that case, you might do:

+
RUST_DEP_GRAPH_FILTER='Hir & foo -> TypeckTables & bar'
+
+

This will dump out all the nodes that lead from Hir(foo) to +TypeckTables(bar), from which you can (hopefully) see the source +of the erroneous edge.

+

Tracking down incorrect edges

+

Sometimes, after you dump the dependency graph, you will find some +path that should not exist, but you will not be quite sure how it came +to be. When the compiler is built with debug assertions, it can +help you track that down. Simply set the RUST_FORBID_DEP_GRAPH_EDGE +environment variable to a filter. Every edge created in the dep-graph +will be tested against that filter – if it matches, a bug! is +reported, so you can easily see the backtrace (RUST_BACKTRACE=1).

+

The syntax for these filters is the same as described in the previous +section. However, note that this filter is applied to every edge +and doesn't handle longer paths in the graph, unlike the previous +section.

+

Example:

+

You find that there is a path from the Hir of foo to the type +check of bar and you don't think there should be. You dump the +dep-graph as described in the previous section and open dep-graph.txt +to see something like:

+
Hir(foo) -> Collect(bar)
+Collect(bar) -> TypeckTables(bar)
+
+

That first edge looks suspicious to you. So you set +RUST_FORBID_DEP_GRAPH_EDGE to Hir&foo -> Collect&bar, re-run, and +then observe the backtrace. Voila, bug fixed!

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/index.html b/index.html new file mode 100644 index 000000000..5173d188d --- /dev/null +++ b/index.html @@ -0,0 +1,339 @@ + + + + + + Getting Started - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Getting Started

+

Thank you for your interest in contributing to Rust! There are many ways to +contribute, and we appreciate all of them.

+ +

If this is your first time contributing, the walkthrough chapter can give you a good example of +how a typical contribution would go.

+

This documentation is not intended to be comprehensive; it is meant to be a +quick guide for the most useful things. For more information, see this +chapter on how to build and run the compiler.

+

Asking Questions

+

If you have questions, please make a post on the Rust Zulip server or +internals.rust-lang.org. If you are contributing to Rustup, be aware they are not on +Zulip - you can ask questions in #wg-rustup on Discord. +See the list of teams and working groups and the Community page on the +official website for more resources.

+

As a reminder, all contributors are expected to follow our Code of Conduct.

+

The compiler team (or t-compiler) usually hangs out in Zulip in this +"stream"; it will be easiest to get questions answered there.

+

Please ask questions! A lot of people report feeling that they are "wasting +expert time", but nobody on t-compiler feels this way. Contributors are +important to us.

+

Also, if you feel comfortable, prefer public topics, as this means others can +see the questions and answers, and perhaps even integrate them back into this +guide :)

+

Experts

+

Not all t-compiler members are experts on all parts of rustc; it's a +pretty large project. To find out who could have some expertise on +different parts of the compiler, consult triagebot assign groups. +The sections that start with [assign* in triagebot.toml file. +But also, feel free to ask questions even if you can't figure out who to ping.

+

Another way to find experts for a given part of the compiler is to see who has made recent commits. +For example, to find people who have recently worked on name resolution since the 1.68.2 release, +you could run git shortlog -n 1.68.2.. compiler/rustc_resolve/. Ignore any commits starting with +"Rollup merge" or commits by @bors (see CI contribution procedures for +more information about these commits).

+

Etiquette

+

We do ask that you be mindful to include as much useful information as you can +in your question, but we recognize this can be hard if you are unfamiliar with +contributing to Rust.

+

Just pinging someone without providing any context can be a bit annoying and +just create noise, so we ask that you be mindful of the fact that the +t-compiler folks get a lot of pings in a day.

+

What should I work on?

+

The Rust project is quite large and it can be difficult to know which parts of the project need +help, or are a good starting place for beginners. Here are some suggested starting places.

+

Easy or mentored issues

+

If you're looking for somewhere to start, check out the following issue +search. See the Triage for an explanation of these labels. You can also try +filtering the search to areas you're interested in. For example:

+
    +
  • repo:rust-lang/rust-clippy will only show clippy issues
  • +
  • label:T-compiler will only show issues related to the compiler
  • +
  • label:A-diagnostics will only show diagnostic issues
  • +
+

Not all important or beginner work has issue labels. +See below for how to find work that isn't labelled.

+

Recurring work

+

Some work is too large to be done by a single person. In this case, it's common to have "Tracking +issues" to co-ordinate the work between contributors. Here are some example tracking issues where +it's easy to pick up work without a large time commitment:

+ +

If you find more recurring work, please feel free to add it here!

+

Clippy issues

+

The Clippy project has spent a long time making its contribution process as friendly to newcomers +as possible. Consider working on it first to get familiar with the process and the compiler +internals.

+

See the Clippy contribution guide for instructions on getting started.

+

Diagnostic issues

+

Many diagnostic issues are self-contained and don't need detailed background knowledge of the +compiler. You can see a list of diagnostic issues here.

+

Picking up abandoned pull requests

+

Sometimes, contributors send a pull request, but later find out that they don't have enough +time to work on it, or they simply are not interested in it anymore. Such PRs are often +eventually closed and they receive the S-inactive label. You could try to examine some of +these PRs and pick up the work. You can find the list of such PRs here.

+

If the PR has been implemented in some other way in the meantime, the S-inactive label +should be removed from it. If not, and it seems that there is still interest in the change, +you can try to rebase the pull request on top of the latest master branch and send a new +pull request, continuing the work on the feature.

+

Contributing to std (standard library)

+

See std-dev-guide.

+

Contributing code to other Rust projects

+

There are a bunch of other projects that you can contribute to outside of the +rust-lang/rust repo, including cargo, miri, rustup, and many others.

+

These repos might have their own contributing guidelines and procedures. Many +of them are owned by working groups. For more info, see the documentation in those repos' READMEs.

+

Other ways to contribute

+

There are a bunch of other ways you can contribute, especially if you don't +feel comfortable jumping straight into the large rust-lang/rust codebase.

+

The following tasks are doable without much background knowledge but are +incredibly helpful:

+
    +
  • Cleanup crew: find minimal reproductions of ICEs, bisect +regressions, etc. This is a way of helping that saves a ton of time for +others to fix an error later.
  • +
  • Writing documentation: if you are feeling a bit more intrepid, you could try +to read a part of the code and write doc comments for it. This will help you +to learn some part of the compiler while also producing a useful artifact!
  • +
  • Triaging issues: categorizing, replicating, and minimizing issues is very helpful to the Rust maintainers.
  • +
  • Working groups: there are a bunch of working groups on a wide variety +of rust-related things.
  • +
  • Answer questions in the Get Help! channels on the Rust Discord +server, on users.rust-lang.org, or on +StackOverflow.
  • +
  • Participate in the RFC process.
  • +
  • Find a requested community library, build it, and publish +it to Crates.io. Easier said than done, but very, very +valuable!
  • +
+

Cloning and Building

+

See "How to build and run the compiler".

+

Contributor Procedures

+

This section has moved to the "Contribution Procedures" chapter.

+

Other Resources

+

This section has moved to the "About this guide" chapter.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/lang-items.html b/lang-items.html new file mode 100644 index 000000000..a90b4a563 --- /dev/null +++ b/lang-items.html @@ -0,0 +1,258 @@ + + + + + + Lang Items - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Lang items

+

The compiler has certain pluggable operations; that is, functionality that isn't hard-coded into +the language, but is implemented in libraries, with a special marker to tell the compiler it +exists. The marker is the attribute #[lang = "..."], and there are various different values of +..., i.e. various different 'lang items'.

+

Many such lang items can be implemented only in one sensible way, such as add (trait core::ops::Add) or future_trait (trait core::future::Future). Others can be overridden to +achieve some specific goals; for example, you can control your binary's entrypoint.

+

Features provided by lang items include:

+
    +
  • overloadable operators via traits: the traits corresponding to the +==, <, dereference (*), +, etc. operators are all +marked with lang items; those specific four are eq, ord, +deref, and add respectively.
  • +
  • panicking and stack unwinding; the eh_personality, panic and +panic_bounds_checks lang items.
  • +
  • the traits in std::marker used to indicate properties of types used by the compiler; +lang items send, sync and copy.
  • +
  • the special marker types used for variance indicators found in +core::marker; lang item phantom_data.
  • +
+

Lang items are loaded lazily by the compiler; e.g. if one never uses Box +then there is no need to define functions for exchange_malloc and +box_free. rustc will emit an error when an item is needed but not found +in the current crate or any that it depends on.

+

Most lang items are defined by the core library, but if you're trying to build an +executable with #![no_std], you'll still need to define a few lang items that are +usually provided by std.

+

Retrieving a language item

+

You can retrieve lang items by calling tcx.lang_items().

+

Here's a small example of retrieving the trait Sized {} language item:

+
#![allow(unused)]
+fn main() {
+// Note that in case of `#![no_core]`, the trait is not available.
+if let Some(sized_trait_def_id) = tcx.lang_items().sized_trait() {
+    // do something with `sized_trait_def_id`
+}
+}
+
+

Note that sized_trait() returns an Option, not the DefId itself. +That's because language items are defined in the standard library, so if someone compiles with +#![no_core] (or for some lang items, #![no_std]), the lang item may not be present. +You can either:

+
    +
  • Give a hard error if the lang item is necessary to continue (don't panic, since this can happen in +user code).
  • +
  • Proceed with limited functionality, by just omitting whatever you were going to do with the +DefId.
  • +
+

List of all language items

+

You can find language items in the following places:

+
    +
  • An exhaustive reference in the compiler documentation: rustc_hir::LangItem
  • +
  • An auto-generated list with source locations by using ripgrep: rg '#\[.*lang =' library/
  • +
+

Note that language items are explicitly unstable and may change in any new release.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/licenses.html b/licenses.html new file mode 100644 index 000000000..45b84d92d --- /dev/null +++ b/licenses.html @@ -0,0 +1,244 @@ + + + + + + Licenses - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

rust-lang/rust Licenses

+

The rustc compiler source and standard library are dual licensed under the Apache License v2.0 and the MIT License unless otherwise specified.

+

Detailed licensing information is available in the COPYRIGHT document of the rust-lang/rust repository.

+

Guidelines for reviewers

+

In general, reviewers need to be looking not only for the code quality of contributions but also +that they are properly licensed. +We have some tips below for things to look out for when reviewing, but if you ever feel uncertain +as to whether some code might be properly licensed, err on the safe side — reach out to the Council +or Compiler Team Leads for feedback!

+

Things to watch out for:

+
    +
  • The PR author states that they copied, ported, or adapted the code from some other source.
  • +
  • There is a comment in the code pointing to a webpage or describing where the algorithm was taken +from.
  • +
  • The algorithm or code pattern seems like it was likely copied from somewhere else.
  • +
  • When adding new dependencies, double check the dependency's license.
  • +
+

In all of these cases, we will want to check that source to make sure it is licensed in a way +that is compatible with Rust’s license.

+

Examples

+
    +
  • Porting C code from a GPL project, like GNU binutils, is not allowed. That would require Rust +itself to be licensed under the GPL.
  • +
  • Copying code from an algorithms text book may be allowed, but some algorithms are patented.
  • +
+

Porting

+

Contributions to rustc, especially around platform and compiler intrinsics, often include porting +over work from other projects, mainly LLVM and GCC.

+

Some general rules apply:

+
    +
  • Copying work needs to adhere to the original license +
      +
    • This applies to direct copy & paste
    • +
    • This also applies to code you looked at and ported
    • +
    +
  • +
+

In general, taking inspiration from other codebases is fine, but please exercise caution when +porting code.

+

Ports of full libraries (e.g. C libraries shipped with LLVM) must keep the license of the original +library.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/llvm-coverage-instrumentation.html b/llvm-coverage-instrumentation.html new file mode 100644 index 000000000..3f89a6c3f --- /dev/null +++ b/llvm-coverage-instrumentation.html @@ -0,0 +1,599 @@ + + + + + + LLVM Source-Based Code Coverage - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

LLVM Source-Based Code Coverage

+ +

rustc supports detailed source-based code and test coverage analysis +with a command line option (-C instrument-coverage) that instruments Rust +libraries and binaries with additional instructions and data, at compile time.

+

The coverage instrumentation injects calls to the LLVM intrinsic instruction +llvm.instrprof.increment at code branches +(based on a MIR-based control flow analysis), and LLVM converts these to +instructions that increment static counters, when executed. The LLVM coverage +instrumentation also requires a Coverage Map that encodes source metadata, +mapping counter IDs--directly and indirectly--to the file locations (with +start and end line and column).

+

Rust libraries, with or without coverage instrumentation, can be linked into +instrumented binaries. When the program is executed and cleanly terminates, +LLVM libraries write the final counter values to a file (default.profraw or +a custom file set through environment variable LLVM_PROFILE_FILE).

+

Developers use existing LLVM coverage analysis tools to decode .profraw +files, with corresponding Coverage Maps (from matching binaries that produced +them), and generate various reports for analysis, for example:

+

Screenshot of sample `llvm-cov show` result, for function add_quoted_string +

+

Detailed instructions and examples are documented in the +rustc book.

+ +

When working on the coverage instrumentation code, it is usually necessary to +enable the profiler runtime by setting profiler = true in [build]. +This allows the compiler to produce instrumented binaries, and makes it possible +to run the full coverage test suite.

+

Enabling debug assertions in the compiler and in LLVM is recommended, but not +mandatory.

+
# Similar to the "compiler" profile, but also enables debug assertions in LLVM.
+# These assertions can detect malformed coverage mappings in some cases.
+profile = "codegen"
+
+[build]
+# IMPORTANT: This tells the build system to build the LLVM profiler runtime.
+# Without it, the compiler can't produce coverage-instrumented binaries,
+# and many of the coverage tests will be skipped.
+profiler = true
+
+[rust]
+# Enable debug assertions in the compiler.
+debug-assertions = true
+
+

Rust symbol mangling

+

-C instrument-coverage automatically enables Rust symbol mangling v0 (as +if the user specified -C symbol-mangling-version=v0 option when invoking +rustc) to ensure consistent and reversible name mangling. This has two +important benefits:

+
    +
  1. LLVM coverage tools can analyze coverage over multiple runs, including some +changes to source code; so mangled names must be consistent across compilations.
  2. +
  3. LLVM coverage reports can report coverage by function, and even separates +out the coverage counts of each unique instantiation of a generic function, +if invoked with multiple type substitution variations.
  4. +
+

Components of LLVM Coverage Instrumentation in rustc

+

LLVM Runtime Dependency

+

Coverage data is only generated by running the executable Rust program. rustc +statically links coverage-instrumented binaries with LLVM runtime code +(compiler-rt) that implements program hooks +(such as an exit hook) to write the counter values to the .profraw file.

+

In the rustc source tree, +library/profiler_builtins bundles the LLVM compiler-rt code into a Rust library crate. +Note that when building rustc, +profiler_builtins is only included when build.profiler = true is set in config.toml.

+

When compiling with -C instrument-coverage, +CrateLoader::postprocess() dynamically loads +profiler_builtins by calling inject_profiler_runtime().

+

MIR Pass: InstrumentCoverage

+

Coverage instrumentation is performed on the MIR with a MIR pass +called InstrumentCoverage. This MIR pass analyzes +the control flow graph (CFG)--represented by MIR BasicBlocks--to identify +code branches, attaches FunctionCoverageInfo to the function's body, +and injects additional Coverage statements into the +BasicBlocks.

+

A MIR Coverage statement is a virtual instruction that indicates a counter +should be incremented when its adjacent statements are executed, to count +a span of code (CodeRegion). It counts the number of times a +branch is executed, and is referred to by coverage mappings in the function's +coverage-info struct.

+

Note that many coverage counters will not be converted into +physical counters (or any other executable instructions) in the final binary. +Some of them will be (see CoverageKind::CounterIncrement), +but other counters can be computed on the fly, when generating a coverage +report, by mapping a CodeRegion to a coverage-counter expression.

+

As an example:

+
#![allow(unused)]
+fn main() {
+fn some_func(flag: bool) {
+    // increment Counter(1)
+    ...
+    if flag {
+        // increment Counter(2)
+        ...
+    } else {
+        // count = Expression(1) = Counter(1) - Counter(2)
+        ...
+    }
+    // count = Expression(2) = Counter(1) + Zero
+    //     or, alternatively, Expression(2) = Counter(2) + Expression(1)
+    ...
+}
+}
+
+

In this example, four contiguous code regions are counted while only +incrementing two counters.

+

CFG analysis is used to not only determine where the branches are, for +conditional expressions like if, else, match, and loop, but also to +determine where expressions can be used in place of physical counters.

+

The advantages of optimizing coverage through expressions are more pronounced +with loops. Loops generally include at least one conditional branch that +determines when to break out of a loop (a while condition, or an if or +match with a break). In MIR, this is typically lowered to a SwitchInt, +with one branch to stay in the loop, and another branch to break out of the +loop. The branch that breaks out will almost always execute less often, +so InstrumentCoverage chooses to add a CounterIncrement to that branch, and +uses an expression (Counter(loop) - Counter(break)) for the branch that +continues.

+

The InstrumentCoverage MIR pass is documented in +more detail below.

+

Counter Injection and Coverage Map Pre-staging

+

When the compiler enters the Codegen phase, with a +coverage-enabled MIR, codegen_statement() converts each +MIR Statement into some backend-specific action or instruction. +codegen_statement() forwards Coverage statements to +codegen_coverage():

+
#![allow(unused)]
+fn main() {
+    pub fn codegen_statement(&mut self, mut bx: Bx, statement: &mir::Statement<'tcx>) -> Bx {
+        ...
+        match statement.kind {
+            ...
+            mir::StatementKind::Coverage(box ref coverage) => {
+                self.codegen_coverage(bx, coverage, statement.source_info.scope);
+            }
+}
+
+

codegen_coverage() handles inlined statements and then forwards the coverage +statement to Builder::add_coverage, which handles each CoverageKind as +follows:

+
    +
  • For both CounterIncrement and ExpressionUsed, the underlying counter or +expression ID is passed through to the corresponding FunctionCoverage +struct to indicate that the corresponding regions of code were not removed +by MIR optimizations.
  • +
  • For CoverageKind::CounterIncrements, an instruction is injected in the backend +IR to increment the physical counter, by calling the BuilderMethod +instrprof_increment().
  • +
+
#![allow(unused)]
+fn main() {
+    fn add_coverage(&mut self, instance: Instance<'tcx>, coverage: &Coverage) {
+        ...
+        let Coverage { kind } = coverage;
+        match *kind {
+            CoverageKind::CounterIncrement { id } => {
+                func_coverage.mark_counter_id_seen(id);
+                ...
+                bx.instrprof_increment(fn_name, hash, num_counters, index);
+            }
+            CoverageKind::ExpressionUsed { id } => {
+                func_coverage.mark_expression_id_seen(id);
+            }
+        }
+    }
+}
+
+
+

The function name instrprof_increment() is taken from the LLVM intrinsic +call of the same name (llvm.instrprof.increment), +and uses the same arguments and types; but note that, up to and through this +stage (even though modeled after LLVM's implementation for code coverage +instrumentation), the data and instructions are not strictly LLVM-specific.

+

But since LLVM is the only Rust-supported backend with the tooling to +process this form of coverage instrumentation, the backend for Coverage +statements is only implemented for LLVM, at this time.

+
+

Coverage Map Generation

+

With the instructions to increment counters now implemented in LLVM IR, +the last remaining step is to inject the LLVM IR variables that hold the +static data for the coverage map.

+

rustc_codegen_llvm's compile_codegen_unit() calls +coverageinfo_finalize(), +which delegates its implementation to the +rustc_codegen_llvm::coverageinfo::mapgen module.

+

For each function Instance (code-generated from MIR, including multiple +instances of the same MIR for generic functions that have different type +substitution combinations), mapgen's finalize() method queries the +Instance-associated FunctionCoverage for its Counters, Expressions, +and CodeRegions; and calls LLVM codegen APIs to generate +properly-configured variables in LLVM IR, according to very specific +details of the LLVM Coverage Mapping Format +(Version 6).1

+
1 +

The Rust compiler (as of Nov 2024) supports LLVM Coverage Mapping Format 6. +The Rust compiler will automatically use the most up-to-date coverage mapping format +version that is compatible with the compiler's built-in version of LLVM.

+
+
#![allow(unused)]
+fn main() {
+pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
+    ...
+    if !tcx.sess.instrument_coverage_except_unused_functions() {
+        add_unused_functions(cx);
+    }
+
+    let mut function_coverage_map = match cx.coverage_context() {
+        Some(ctx) => ctx.take_function_coverage_map(),
+        None => return,
+    };
+    ...
+    let mut mapgen = CoverageMapGenerator::new();
+
+    for (instance, function_coverage) in function_coverage_map {
+        ...
+        let coverage_mapping_buffer = llvm::build_byte_buffer(|coverage_mapping_buffer| {
+            mapgen.write_coverage_mapping(expressions, counter_regions, coverage_mapping_buffer);
+        });
+}
+
+

code snippet trimmed for brevity

+

One notable first step performed by mapgen::finalize() is the call to +add_unused_functions():

+

When finalizing the coverage map, FunctionCoverage only has the CodeRegions +and counters for the functions that went through codegen; such as public +functions and "used" functions (functions referenced by other "used" or public +items). Any other functions (considered unused) were still parsed and processed +through the MIR stage.

+

The set of unused functions is computed via the set difference of all MIR +DefIds (tcx query mir_keys) minus the codegenned DefIds (tcx query +codegened_and_inlined_items). add_unused_functions() computes the set of +unused functions, queries the tcx for the previously-computed CodeRegions, +for each unused MIR, synthesizes an LLVM function (with no internal statements, +since it will not be called), and adds a new FunctionCoverage, with +Unreachable code regions.

+

Testing LLVM Coverage

+

(See also the compiletest documentation for the tests/coverage +test suite.)

+

Coverage instrumentation in the MIR is validated by a mir-opt test: +tests/mir-opt/coverage/instrument_coverage.rs.

+

Coverage instrumentation in LLVM IR is validated by the tests/coverage +test suite in coverage-map mode. +These tests compile a test program to LLVM IR assembly, and then +use the src/tools/coverage-dump tool to extract and pretty-print the +coverage mappings that would be embedded in the final binary.

+

End-to-end testing of coverage instrumentation and coverage reporting is +performed by the tests/coverage test suite in coverage-run mode, +and by the tests/coverage-run-rustdoc test suite. +These tests compile and run a test program with coverage +instrumentation, then use LLVM tools to convert the coverage data into a +human-readable coverage report.

+
+

Tests in coverage-run mode have an implicit //@ needs-profiler-runtime +directive, so they will be skipped if the profiler runtime has not been +enabled in config.toml.

+
+

Finally, the tests/codegen/instrument-coverage/testprog.rs test compiles a simple Rust program +with -C instrument-coverage and compares the compiled program's LLVM IR to +expected LLVM IR instructions and structured data for a coverage-enabled +program, including various checks for Coverage Map-related metadata and the LLVM +intrinsic calls to increment the runtime counters.

+

Expected results for the coverage, coverage-run-rustdoc, +and mir-opt tests can be refreshed by running:

+
./x test coverage --bless
+./x test coverage-run-rustdoc --bless
+./x test tests/mir-opt --bless
+
+

Implementation Details of the InstrumentCoverage MIR Pass

+

The bulk of the implementation of the InstrumentCoverage MIR pass is performed +by instrument_function_for_coverage. For each eligible MIR body, the instrumentor:

+
    +
  • Prepares a coverage graph
  • +
  • Extracts mapping information from MIR
  • +
  • Prepares counters for each relevant node/edge in the coverage graph
  • +
  • Creates mapping data to be embedded in side-tables attached to the MIR body
  • +
  • Injects counters and other coverage statements into MIR
  • +
+

The coverage graph is a coverage-specific simplification of the MIR control +flow graph (CFG). Its nodes are BasicCoverageBlocks, which +encompass one or more sequentially-executed MIR BasicBlocks +(with no internal branching).

+

Nodes and edges in the graph can have associated BcbCounters, which are +stored in CoverageCounters.

+

The CoverageGraph

+

The CoverageGraph is derived from the MIR (mir::Body).

+
#![allow(unused)]
+fn main() {
+        let basic_coverage_blocks = CoverageGraph::from_mir(mir_body);
+}
+
+

Like mir::Body, the CoverageGraph is also a +DirectedGraph. Both graphs represent the function's +fundamental control flow, with many of the same +graph traits, supporting start_node(), num_nodes(), +successors(), predecessors(), and is_dominated_by().

+

For anyone that knows how to work with the MIR, as a CFG, the +CoverageGraph will be familiar, and can be used in much the same way. +The nodes of the CoverageGraph are BasicCoverageBlocks (BCBs), which +index into an IndexVec of BasicCoverageBlockData. This is analogous +to the MIR CFG of BasicBlocks that index BasicBlockData.

+

Each BasicCoverageBlockData captures one or more MIR BasicBlocks, +exclusively, and represents the maximal-length sequence of BasicBlocks +without conditional branches.

+

compute_basic_coverage_blocks() builds the +CoverageGraph as a coverage-specific simplification of the MIR CFG. In +contrast with the SimplifyCfg MIR pass, this step does +not alter the MIR itself, because the CoverageGraph aggressively simplifies +the CFG, and ignores nodes that are not relevant to coverage. For example:

+
    +
  • The BCB CFG ignores (excludes) branches considered not relevant +to the current coverage solution. It excludes unwind-related code2 +that is injected by the Rust compiler but has no physical source +code to count, which allows a Call-terminated BasicBlock +to be merged with its successor, within a single BCB.
  • +
  • A Goto-terminated BasicBlock can be merged with its successor +as long as it has the only incoming edge to the successor +BasicBlock.
  • +
  • Some BasicBlock terminators support Rust-specific concerns--like +borrow-checking--that are not relevant to coverage analysis. FalseUnwind, +for example, can be treated the same as a Goto (potentially merged with +its successor into the same BCB).
  • +
+
2 +

(Note, however, that Issue #78544 considers +providing future support for coverage of programs that intentionally +panic, as an option, with some non-trivial cost.)

+
+

The BCB CFG is critical to simplifying the coverage analysis by ensuring graph path-based +queries (is_dominated_by(), predecessors, successors, etc.) have branch (control flow) +significance.

+

make_bcb_counters()

+

make_bcb_counters traverses the CoverageGraph and adds a +Counter or Expression to every BCB. It uses Control Flow Analysis +to determine where an Expression can be used in place of a Counter. +Expressions have no runtime overhead, so if a viable expression (adding or +subtracting two other counters or expressions) can compute the same result as +an embedded counter, an Expression is preferred.

+

TraverseCoverageGraphWithLoops +provides a traversal order that ensures all BasicCoverageBlock nodes in a +loop are visited before visiting any node outside that loop. The traversal +state includes a context_stack, with the current loop's context information +(if in a loop), as well as context for nested loops.

+

Within loops, nodes with multiple outgoing edges (generally speaking, these +are BCBs terminated in a SwitchInt) can be optimized when at least one +branch exits the loop and at least one branch stays within the loop. (For an +if or while, there are only two branches, but a match may have more.)

+

A branch that does not exit the loop should be counted by Expression, if +possible. Note that some situations require assigning counters to BCBs before +they are visited by traversal, so the counter_kind (CoverageKind for +a Counter or Expression) may have already been assigned, in which case +one of the other branches should get the Expression.

+

For a node with more than two branches (such as for more than two +match patterns), only one branch can be optimized by Expression. All +others require a Counter (unless its BCB counter_kind was previously +assigned).

+

A branch expression is derived from the equation:

+
Counter(branching_node) = SUM(Counter(branches))
+
+

It's important to +be aware that the branches in this equation are the outgoing edges +from the branching_node, but a branch's target node may have other +incoming edges. Given the following graph, for example, the count for +B is the sum of its two incoming edges:

+

Example graph with multiple incoming edges to a branch node +

+

In this situation, BCB node B may require an edge counter for its +"edge from A", and that edge might be computed from an Expression, +Counter(A) - Counter(C). But an expression for the BCB node B +would be the sum of all incoming edges:

+
Expression((Counter(A) - Counter(C)) + SUM(Counter(remaining_edges)))
+
+

Note that this is only one possible configuration. The actual choice +of Counter vs. Expression also depends on the order of counter +assignments, and whether a BCB or incoming edge counter already has +its Counter or Expression.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/macro-expansion.html b/macro-expansion.html new file mode 100644 index 000000000..a5ce5aa85 --- /dev/null +++ b/macro-expansion.html @@ -0,0 +1,675 @@ + + + + + + Macro expansion - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Macro expansion

+ +
+

N.B. rustc_ast, rustc_expand, and rustc_builtin_macros are all +undergoing refactoring, so some of the links in this chapter may be broken.

+
+

Rust has a very powerful macro system. In the previous chapter, we saw how +the parser sets aside macros to be expanded (using temporary placeholders). +This chapter is about the process of expanding those macros iteratively until +we have a complete Abstract Syntax Tree (AST) for our crate with no +unexpanded macros (or a compile error).

+

First, we discuss the algorithm that expands and integrates macro output into +ASTs. Next, we take a look at how hygiene data is collected. Finally, we look +at the specifics of expanding different types of macros.

+

Many of the algorithms and data structures described below are in rustc_expand, +with fundamental data structures in rustc_expand::base.

+

Also of note, cfg and cfg_attr are treated specially from other macros, and are +handled in rustc_expand::config.

+

Expansion and AST Integration

+

Firstly, expansion happens at the crate level. Given a raw source code for +a crate, the compiler will produce a massive AST with all macros expanded, all +modules inlined, etc. The primary entry point for this process is the +MacroExpander::fully_expand_fragment method. With few exceptions, we +use this method on the whole crate (see "Eager Expansion" +below for more detailed discussion of edge case expansion issues).

+

At a high level, fully_expand_fragment works in iterations. We keep a +queue of unresolved macro invocations (i.e. macros we haven't found the +definition of yet). We repeatedly try to pick a macro from the queue, resolve +it, expand it, and integrate it back. If we can't make progress in an +iteration, this represents a compile error. Here is the algorithm:

+
    +
  1. Initialize a queue of unresolved macros.
  2. +
  3. Repeat until queue is empty (or we make no progress, which is an error): +
      +
    1. Resolve imports in our partially built crate as +much as possible.
    2. +
    3. Collect as many macro Invocations as possible from our +partially built crate (fn-like, attributes, derives) and add them to the +queue.
    4. +
    5. Dequeue the first element and attempt to resolve it.
    6. +
    7. If it's resolved: +
        +
      1. Run the macro's expander function that consumes a TokenStream or +AST and produces a TokenStream or AstFragment (depending on +the macro kind). (A TokenStream is a collection of TokenTrees, +each of which are a token (punctuation, identifier, or literal) or a +delimited group (anything inside ()/[]/{})). +
          +
        • At this point, we know everything about the macro itself and can +call set_expn_data to fill in its properties in the global +data; that is the hygiene data associated with ExpnId (see +Hygiene below).
        • +
        +
      2. +
      3. Integrate that piece of AST into the currently-existing though +partially-built AST. This is essentially where the "token-like mass" +becomes a proper set-in-stone AST with side-tables. It happens as +follows: +
          +
        • If the macro produces tokens (e.g. a proc macro), we parse into +an AST, which may produce parse errors.
        • +
        • During expansion, we create SyntaxContexts (hierarchy 2) (see +Hygiene below).
        • +
        • These three passes happen one after another on every AST fragment +freshly expanded from a macro: + +
        • +
        +
      4. +
      5. After expanding a single macro and integrating its output, continue +to the next iteration of fully_expand_fragment.
      6. +
      +
    8. +
    9. If it's not resolved: +
        +
      1. Put the macro back in the queue.
      2. +
      3. Continue to next iteration...
      4. +
      +
    10. +
    +
  4. +
+

Error Recovery

+

If we make no progress in an iteration we have reached a compilation error +(e.g. an undefined macro). We attempt to recover from failures (i.e. +unresolved macros or imports) with the intent of generating diagnostics. +Failure recovery happens by expanding unresolved macros into +ExprKind::Err and allows compilation to continue past the first error +so that rustc can report more errors than just the original failure.

+

Name Resolution

+

Notice that name resolution is involved here: we need to resolve imports and +macro names in the above algorithm. This is done in +rustc_resolve::macros, which resolves macro paths, validates +those resolutions, and reports various errors (e.g. "not found", "found, but +it's unstable", "expected x, found y"). However, we don't try to resolve +other names yet. This happens later, as we will see in the chapter: Name +Resolution.

+

Eager Expansion

+

Eager expansion means we expand the arguments of a macro invocation before +the macro invocation itself. This is implemented only for a few special +built-in macros that expect literals; expanding arguments first for some of +these macro results in a smoother user experience. As an example, consider +the following:

+
macro bar($i: ident) { $i }
+macro foo($i: ident) { $i }
+
+foo!(bar!(baz));
+
+

A lazy-expansion would expand foo! first. An eager-expansion would expand +bar! first.

+

Eager-expansion is not a generally available feature of Rust. Implementing +eager-expansion more generally would be challenging, so we implement it for a +few special built-in macros for the sake of user-experience. The built-in +macros are implemented in rustc_builtin_macros, along with some other +early code generation facilities like injection of standard library imports or +generation of test harness. There are some additional helpers for building +AST fragments in rustc_expand::build. Eager-expansion generally +performs a subset of the things that lazy (normal) expansion does. It is done +by invoking fully_expand_fragment on only part of a crate (as opposed +to the whole crate, like we normally do).

+

Other Data Structures

+

Here are some other notable data structures involved in expansion and +integration:

+
    +
  • ResolverExpand - a trait used to break crate dependencies. This allows the +resolver services to be used in rustc_ast, despite rustc_resolve and +pretty much everything else depending on rustc_ast.
  • +
  • ExtCtxt/ExpansionData - holds various intermediate expansion +infrastructure data.
  • +
  • Annotatable - a piece of AST that can be an attribute target, almost the same +thing as AstFragment except for types and patterns that can be produced by +macros but cannot be annotated with attributes.
  • +
  • MacResult - a "polymorphic" AST fragment, something that can turn into +a different AstFragment depending on its AstFragmentKind (i.e. an item, +expression, pattern, etc).
  • +
+

Hygiene and Hierarchies

+

If you have ever used the C/C++ preprocessor macros, you know that there are some +annoying and hard-to-debug gotchas! For example, consider the following C code:

+
#define DEFINE_FOO struct Bar {int x;}; struct Foo {Bar bar;};
+
+// Then, somewhere else
+struct Bar {
+    ...
+};
+
+DEFINE_FOO
+
+

Most people avoid writing C like this – and for good reason: it doesn't +compile. The struct Bar defined by the macro clashes names with the struct Bar defined in the code. Consider also the following example:

+
#define DO_FOO(x) {\
+    int y = 0;\
+    foo(x, y);\
+    }
+
+// Then elsewhere
+int y = 22;
+DO_FOO(y);
+
+

Do you see the problem? We wanted to generate a call foo(22, 0), but instead +we got foo(0, 0) because the macro defined its own y!

+

These are both examples of macro hygiene issues. Hygiene relates to how to +handle names defined within a macro. In particular, a hygienic macro system +prevents errors due to names introduced within a macro. Rust macros are hygienic +in that they do not allow one to write the sorts of bugs above.

+

At a high level, hygiene within the Rust compiler is accomplished by keeping +track of the context where a name is introduced and used. We can then +disambiguate names based on that context. Future iterations of the macro system +will allow greater control to the macro author to use that context. For example, +a macro author may want to introduce a new name to the context where the macro +was called. Alternately, the macro author may be defining a variable for use +only within the macro (i.e. it should not be visible outside the macro).

+

The context is attached to AST nodes. All AST nodes generated by macros have +context attached. Additionally, there may be other nodes that have context +attached, such as some desugared syntax (non-macro-expanded nodes are +considered to just have the "root" context, as described below). +Throughout the compiler, we use rustc_span::Spans to refer to code locations. +This struct also has hygiene information attached to it, as we will see later.

+

Because macros invocations and definitions can be nested, the syntax context of +a node must be a hierarchy. For example, if we expand a macro and there is +another macro invocation or definition in the generated output, then the syntax +context should reflect the nesting.

+

However, it turns out that there are actually a few types of context we may +want to track for different purposes. Thus, there are not just one but three +expansion hierarchies that together comprise the hygiene information for a +crate.

+

All of these hierarchies need some sort of "macro ID" to identify individual +elements in the chain of expansions. This ID is ExpnId. All macros receive +an integer ID, assigned continuously starting from 0 as we discover new macro +calls. All hierarchies start at ExpnId::root, which is its own +parent.

+

The rustc_span::hygiene crate contains all of the hygiene-related algorithms +(with the exception of some hacks in Resolver::resolve_crate_root) +and structures related to hygiene and expansion that are kept in global data.

+

The actual hierarchies are stored in HygieneData. This is a global +piece of data containing hygiene and expansion info that can be accessed from +any Ident without any context.

+

The Expansion Order Hierarchy

+

The first hierarchy tracks the order of expansions, i.e., when a macro +invocation is in the output of another macro.

+

Here, the children in the hierarchy will be the "innermost" tokens. The +ExpnData struct itself contains a subset of properties from both macro +definition and macro call available through global data. +ExpnData::parent tracks the child-to-parent link in this hierarchy.

+

For example:

+
macro_rules! foo { () => { println!(); } }
+
+fn main() { foo!(); }
+
+

In this code, the AST nodes that are finally generated would have hierarchy +root -> id(foo) -> id(println).

+

The Macro Definition Hierarchy

+

The second hierarchy tracks the order of macro definitions, i.e., when we are +expanding one macro another macro definition is revealed in its output. This +one is a bit tricky and more complex than the other two hierarchies.

+

SyntaxContext represents a whole chain in this hierarchy via an ID. +SyntaxContextData contains data associated with the given +SyntaxContext; mostly it is a cache for results of filtering that chain in +different ways. SyntaxContextData::parent is the child-to-parent +link here, and SyntaxContextData::outer_expns are individual +elements in the chain. The "chaining-operator" is +SyntaxContext::apply_mark in compiler code.

+

A Span, mentioned above, is actually just a compact representation of +a code location and SyntaxContext. Likewise, an Ident is just an interned +Symbol + Span (i.e. an interned string + hygiene data).

+

For built-in macros, we use the context: +SyntaxContext::empty().apply_mark(expn_id), and such macros are +considered to be defined at the hierarchy root. We do the same for proc macros because we haven't implemented cross-crate hygiene yet.

+

If the token had context X before being produced by a macro then after being +produced by the macro it has context X -> macro_id. Here are some examples:

+

Example 0:

+
macro m() { ident }
+
+m!();
+
+

Here ident which initially has context SyntaxContext::root has +context ROOT -> id(m) after it's produced by m.

+

Example 1:

+
macro m() { macro n() { ident } }
+
+m!();
+n!();
+
+

In this example the ident has context ROOT initially, then ROOT -> id(m) +after the first expansion, then ROOT -> id(m) -> id(n).

+

Example 2:

+

Note that these chains are not entirely determined by their last element, in +other words ExpnId is not isomorphic to SyntaxContext.

+
macro m($i: ident) { macro n() { ($i, bar) } }
+
+m!(foo);
+
+

After all expansions, foo has context ROOT -> id(n) and bar has context +ROOT -> id(m) -> id(n).

+

Currently this hierarchy for tracking macro definitions is subject to the +so-called "context transplantation hack". Modern (i.e. experimental) +macros have stronger hygiene than the legacy "Macros By Example" (MBE) +system which can result in weird interactions between the two. The hack is +intended to make things "just work" for now.

+

The Call-site Hierarchy

+

The third and final hierarchy tracks the location of macro invocations.

+

In this hierarchy ExpnData::call_site is the child -> parent +link.

+

Here is an example:

+
macro bar($i: ident) { $i }
+macro foo($i: ident) { $i }
+
+foo!(bar!(baz));
+
+

For the baz AST node in the final output, the expansion-order hierarchy is +ROOT -> id(foo) -> id(bar) -> baz, while the call-site hierarchy is ROOT -> baz.

+

Macro Backtraces

+

Macro backtraces are implemented in rustc_span using the hygiene machinery +in rustc_span::hygiene.

+

Producing Macro Output

+

Above, we saw how the output of a macro is integrated into the AST for a crate, +and we also saw how the hygiene data for a crate is generated. But how do we +actually produce the output of a macro? It depends on the type of macro.

+

There are two types of macros in Rust:

+
    +
  1. macro_rules! macros (a.k.a. "Macros By Example" (MBE)), and,
  2. +
  3. procedural macros (proc macros); including custom derives.
  4. +
+

During the parsing phase, the normal Rust parser will set aside the contents of +macros and their invocations. Later, macros are expanded using these +portions of the code.

+

Some important data structures/interfaces here:

+ +

Macros By Example

+

MBEs have their own parser distinct from the Rust parser. When macros are +expanded, we may invoke the MBE parser to parse and expand a macro. The +MBE parser, in turn, may call the Rust parser when it needs to bind a +metavariable (e.g. $my_expr) while parsing the contents of a macro +invocation. The code for macro expansion is in +compiler/rustc_expand/src/mbe/.

+

Example

+
macro_rules! printer {
+    (print $mvar:ident) => {
+        println!("{}", $mvar);
+    };
+    (print twice $mvar:ident) => {
+        println!("{}", $mvar);
+        println!("{}", $mvar);
+    };
+}
+
+

Here $mvar is called a metavariable. Unlike normal variables, rather than +binding to a value at runtime, a metavariable binds at compile time to a +tree of tokens. A token is a single "unit" of the grammar, such as an +identifier (e.g. foo) or punctuation (e.g. =>). There are also other +special tokens, such as EOF, which its self indicates that there are no more +tokens. There are token trees resulting from the paired parentheses-like +characters ((...), [...], and {...}) – they include the open and +close and all the tokens in between (Rust requires that parentheses-like +characters be balanced). Having macro expansion operate on token streams +rather than the raw bytes of a source-file abstracts away a lot of complexity. +The macro expander (and much of the rest of the compiler) doesn't consider +the exact line and column of some syntactic construct in the code; it considers +which constructs are used in the code. Using tokens allows us to care about +what without worrying about where. For more information about tokens, see +the Parsing chapter of this book.

+
printer!(print foo); // `foo` is a variable
+
+

The process of expanding the macro invocation into the syntax tree +println!("{}", foo) and then expanding the syntax tree into a call to +Display::fmt is one common example of macro expansion.

+

The MBE parser

+

There are two parts to MBE expansion done by the macro parser:

+
    +
  1. parsing the definition, and,
  2. +
  3. parsing the invocations.
  4. +
+

We think of the MBE parser as a nondeterministic finite automaton (NFA) based +regex parser since it uses an algorithm similar in spirit to the Earley +parsing algorithm. The macro +parser is defined in +compiler/rustc_expand/src/mbe/macro_parser.rs.

+

The interface of the macro parser is as follows (this is slightly simplified):

+
fn parse_tt(
+    &mut self,
+    parser: &mut Cow<'_, Parser<'_>>,
+    matcher: &[MatcherLoc]
+) -> ParseResult
+
+

We use these items in macro parser:

+
    +
  • a parser variable is a reference to the state of a normal Rust parser, +including the token stream and parsing session. The token stream is what we +are about to ask the MBE parser to parse. We will consume the raw stream of +tokens and output a binding of metavariables to corresponding token trees. +The parsing session can be used to report parser errors.
  • +
  • a matcher variable is a sequence of MatcherLocs that we want to match +the token stream against. They're converted from token trees before matching.
  • +
+

In the analogy of a regex parser, the token stream is the input and we are +matching it against the pattern defined by matcher. Using our examples, the +token stream could be the stream of tokens containing the inside of the example +invocation print foo, while matcher might be the sequence of token (trees) +print $mvar:ident.

+

The output of the parser is a ParseResult, which indicates which of +three cases has occurred:

+
    +
  • Success: the token stream matches the given matcher and we have produced a +binding from metavariables to the corresponding token trees.
  • +
  • Failure: the token stream does not match matcher and results in an error +message such as "No rule expected token ...".
  • +
  • Error: some fatal error has occurred in the parser. For example, this +happens if there is more than one pattern match, since that indicates the +macro is ambiguous.
  • +
+

The full interface is defined here.

+

The macro parser does pretty much exactly the same as a normal regex parser +with one exception: in order to parse different types of metavariables, such as +ident, block, expr, etc., the macro parser must call back to the normal +Rust parser. Both the definition and invocation of macros are parsed using +the parser in a process which is non-intuitively self-referential.

+

The code to parse macro definitions is in +compiler/rustc_expand/src/mbe/macro_rules.rs. It defines the +pattern for matching a macro definition as $( $lhs:tt => $rhs:tt );+. In +other words, a macro_rules definition should have in its body at least one +occurrence of a token tree followed by => followed by another token tree. +When the compiler comes to a macro_rules definition, it uses this pattern to +match the two token trees per the rules of the definition of the macro, thereby +utilizing the macro parser itself. In our example definition, the +metavariable $lhs would match the patterns of both arms: (print $mvar:ident) and (print twice $mvar:ident). And $rhs would match the +bodies of both arms: { println!("{}", $mvar); } and { println!("{}", $mvar); println!("{}", $mvar); }. The parser keeps this knowledge around for when it +needs to expand a macro invocation.

+

When the compiler comes to a macro invocation, it parses that invocation using +a NFA-based macro parser described above. However, the matcher variable +used is the first token tree ($lhs) extracted from the arms of the macro +definition. Using our example, we would try to match the token stream print foo from the invocation against the matchers print $mvar:ident and print twice $mvar:ident that we previously extracted from the definition. The +algorithm is exactly the same, but when the macro parser comes to a place in the +current matcher where it needs to match a non-terminal (e.g. $mvar:ident), +it calls back to the normal Rust parser to get the contents of that +non-terminal. In this case, the Rust parser would look for an ident token, +which it finds (foo) and returns to the macro parser. Then, the macro parser +proceeds in parsing as normal. Also, note that exactly one of the matchers from +the various arms should match the invocation; if there is more than one match, +the parse is ambiguous, while if there are no matches at all, there is a syntax +error.

+

For more information about the macro parser's implementation, see the comments +in compiler/rustc_expand/src/mbe/macro_parser.rs.

+

Procedural Macros

+

Procedural macros are also expanded during parsing. However, rather than +having a parser in the compiler, proc macros are implemented as custom, +third-party crates. The compiler will compile the proc macro crate and +specially annotated functions in them (i.e. the proc macro itself), passing +them a stream of tokens. A proc macro can then transform the token stream and +output a new token stream, which is synthesized into the AST.

+

The token stream type used by proc macros is stable, so rustc does not +use it internally. The compiler's (unstable) token stream is defined in +rustc_ast::tokenstream::TokenStream. This is converted into the +stable proc_macro::TokenStream and back in +rustc_expand::proc_macro and rustc_expand::proc_macro_server. +Since the Rust ABI is currently unstable, we use the C ABI for this conversion.

+ +

Custom Derive

+

Custom derives are a special type of proc macro.

+

Macros By Example and Macros 2.0

+

There is an legacy and mostly undocumented effort to improve the MBE system +by giving it more hygiene-related features, better scoping and visibility +rules, etc. Internally this uses the same machinery as today's MBEs with some +additional syntactic sugar and are allowed to be in namespaces.

+ + +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/mark.min.js b/mark.min.js new file mode 100644 index 000000000..163623188 --- /dev/null +++ b/mark.min.js @@ -0,0 +1,7 @@ +/*!*************************************************** +* mark.js v8.11.1 +* https://markjs.io/ +* Copyright (c) 2014–2018, Julian Kühnel +* Released under the MIT license https://git.io/vwTVl +*****************************************************/ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Mark=t()}(this,function(){"use strict";var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var n=0;n1&&void 0!==arguments[1])||arguments[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:5e3;t(this,e),this.ctx=n,this.iframes=r,this.exclude=i,this.iframesTimeout=o}return n(e,[{key:"getContexts",value:function(){var e=[];return(void 0!==this.ctx&&this.ctx?NodeList.prototype.isPrototypeOf(this.ctx)?Array.prototype.slice.call(this.ctx):Array.isArray(this.ctx)?this.ctx:"string"==typeof this.ctx?Array.prototype.slice.call(document.querySelectorAll(this.ctx)):[this.ctx]:[]).forEach(function(t){var n=e.filter(function(e){return e.contains(t)}).length>0;-1!==e.indexOf(t)||n||e.push(t)}),e}},{key:"getIframeContents",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},r=void 0;try{var i=e.contentWindow;if(r=i.document,!i||!r)throw new Error("iframe inaccessible")}catch(e){n()}r&&t(r)}},{key:"isIframeBlank",value:function(e){var t="about:blank",n=e.getAttribute("src").trim();return e.contentWindow.location.href===t&&n!==t&&n}},{key:"observeIframeLoad",value:function(e,t,n){var r=this,i=!1,o=null,a=function a(){if(!i){i=!0,clearTimeout(o);try{r.isIframeBlank(e)||(e.removeEventListener("load",a),r.getIframeContents(e,t,n))}catch(e){n()}}};e.addEventListener("load",a),o=setTimeout(a,this.iframesTimeout)}},{key:"onIframeReady",value:function(e,t,n){try{"complete"===e.contentWindow.document.readyState?this.isIframeBlank(e)?this.observeIframeLoad(e,t,n):this.getIframeContents(e,t,n):this.observeIframeLoad(e,t,n)}catch(e){n()}}},{key:"waitForIframes",value:function(e,t){var n=this,r=0;this.forEachIframe(e,function(){return!0},function(e){r++,n.waitForIframes(e.querySelector("html"),function(){--r||t()})},function(e){e||t()})}},{key:"forEachIframe",value:function(t,n,r){var i=this,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},a=t.querySelectorAll("iframe"),s=a.length,c=0;a=Array.prototype.slice.call(a);var u=function(){--s<=0&&o(c)};s||u(),a.forEach(function(t){e.matches(t,i.exclude)?u():i.onIframeReady(t,function(e){n(t)&&(c++,r(e)),u()},u)})}},{key:"createIterator",value:function(e,t,n){return document.createNodeIterator(e,t,n,!1)}},{key:"createInstanceOnIframe",value:function(t){return new e(t.querySelector("html"),this.iframes)}},{key:"compareNodeIframe",value:function(e,t,n){if(e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_PRECEDING){if(null===t)return!0;if(t.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING)return!0}return!1}},{key:"getIteratorNode",value:function(e){var t=e.previousNode();return{prevNode:t,node:null===t?e.nextNode():e.nextNode()&&e.nextNode()}}},{key:"checkIframeFilter",value:function(e,t,n,r){var i=!1,o=!1;return r.forEach(function(e,t){e.val===n&&(i=t,o=e.handled)}),this.compareNodeIframe(e,t,n)?(!1!==i||o?!1===i||o||(r[i].handled=!0):r.push({val:n,handled:!0}),!0):(!1===i&&r.push({val:n,handled:!1}),!1)}},{key:"handleOpenIframes",value:function(e,t,n,r){var i=this;e.forEach(function(e){e.handled||i.getIframeContents(e.val,function(e){i.createInstanceOnIframe(e).forEachNode(t,n,r)})})}},{key:"iterateThroughNodes",value:function(e,t,n,r,i){for(var o,a=this,s=this.createIterator(t,e,r),c=[],u=[],l=void 0,h=void 0;void 0,o=a.getIteratorNode(s),h=o.prevNode,l=o.node;)this.iframes&&this.forEachIframe(t,function(e){return a.checkIframeFilter(l,h,e,c)},function(t){a.createInstanceOnIframe(t).forEachNode(e,function(e){return u.push(e)},r)}),u.push(l);u.forEach(function(e){n(e)}),this.iframes&&this.handleOpenIframes(c,e,n,r),i()}},{key:"forEachNode",value:function(e,t,n){var r=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},o=this.getContexts(),a=o.length;a||i(),o.forEach(function(o){var s=function(){r.iterateThroughNodes(e,o,t,n,function(){--a<=0&&i()})};r.iframes?r.waitForIframes(o,s):s()})}}],[{key:"matches",value:function(e,t){var n="string"==typeof t?[t]:t,r=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector;if(r){var i=!1;return n.every(function(t){return!r.call(e,t)||(i=!0,!1)}),i}return!1}}]),e}(),o=function(){function e(n){t(this,e),this.opt=r({},{diacritics:!0,synonyms:{},accuracy:"partially",caseSensitive:!1,ignoreJoiners:!1,ignorePunctuation:[],wildcards:"disabled"},n)}return n(e,[{key:"create",value:function(e){return"disabled"!==this.opt.wildcards&&(e=this.setupWildcardsRegExp(e)),e=this.escapeStr(e),Object.keys(this.opt.synonyms).length&&(e=this.createSynonymsRegExp(e)),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),this.opt.diacritics&&(e=this.createDiacriticsRegExp(e)),e=this.createMergedBlanksRegExp(e),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.createJoinersRegExp(e)),"disabled"!==this.opt.wildcards&&(e=this.createWildcardsRegExp(e)),e=this.createAccuracyRegExp(e),new RegExp(e,"gm"+(this.opt.caseSensitive?"":"i"))}},{key:"escapeStr",value:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}},{key:"createSynonymsRegExp",value:function(e){var t=this.opt.synonyms,n=this.opt.caseSensitive?"":"i",r=this.opt.ignoreJoiners||this.opt.ignorePunctuation.length?"\0":"";for(var i in t)if(t.hasOwnProperty(i)){var o=t[i],a="disabled"!==this.opt.wildcards?this.setupWildcardsRegExp(i):this.escapeStr(i),s="disabled"!==this.opt.wildcards?this.setupWildcardsRegExp(o):this.escapeStr(o);""!==a&&""!==s&&(e=e.replace(new RegExp("("+this.escapeStr(a)+"|"+this.escapeStr(s)+")","gm"+n),r+"("+this.processSynonyms(a)+"|"+this.processSynonyms(s)+")"+r))}return e}},{key:"processSynonyms",value:function(e){return(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),e}},{key:"setupWildcardsRegExp",value:function(e){return(e=e.replace(/(?:\\)*\?/g,function(e){return"\\"===e.charAt(0)?"?":""})).replace(/(?:\\)*\*/g,function(e){return"\\"===e.charAt(0)?"*":""})}},{key:"createWildcardsRegExp",value:function(e){var t="withSpaces"===this.opt.wildcards;return e.replace(/\u0001/g,t?"[\\S\\s]?":"\\S?").replace(/\u0002/g,t?"[\\S\\s]*?":"\\S*")}},{key:"setupIgnoreJoinersRegExp",value:function(e){return e.replace(/[^(|)\\]/g,function(e,t,n){var r=n.charAt(t+1);return/[(|)\\]/.test(r)||""===r?e:e+"\0"})}},{key:"createJoinersRegExp",value:function(e){var t=[],n=this.opt.ignorePunctuation;return Array.isArray(n)&&n.length&&t.push(this.escapeStr(n.join(""))),this.opt.ignoreJoiners&&t.push("\\u00ad\\u200b\\u200c\\u200d"),t.length?e.split(/\u0000+/).join("["+t.join("")+"]*"):e}},{key:"createDiacriticsRegExp",value:function(e){var t=this.opt.caseSensitive?"":"i",n=this.opt.caseSensitive?["aàáảãạăằắẳẵặâầấẩẫậäåāą","AÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ","cçćč","CÇĆČ","dđď","DĐĎ","eèéẻẽẹêềếểễệëěēę","EÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ","iìíỉĩịîïī","IÌÍỈĨỊÎÏĪ","lł","LŁ","nñňń","NÑŇŃ","oòóỏõọôồốổỗộơởỡớờợöøō","OÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ","rř","RŘ","sšśșş","SŠŚȘŞ","tťțţ","TŤȚŢ","uùúủũụưừứửữựûüůū","UÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ","yýỳỷỹỵÿ","YÝỲỶỸỴŸ","zžżź","ZŽŻŹ"]:["aàáảãạăằắẳẵặâầấẩẫậäåāąAÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ","cçćčCÇĆČ","dđďDĐĎ","eèéẻẽẹêềếểễệëěēęEÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ","iìíỉĩịîïīIÌÍỈĨỊÎÏĪ","lłLŁ","nñňńNÑŇŃ","oòóỏõọôồốổỗộơởỡớờợöøōOÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ","rřRŘ","sšśșşSŠŚȘŞ","tťțţTŤȚŢ","uùúủũụưừứửữựûüůūUÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ","yýỳỷỹỵÿYÝỲỶỸỴŸ","zžżźZŽŻŹ"],r=[];return e.split("").forEach(function(i){n.every(function(n){if(-1!==n.indexOf(i)){if(r.indexOf(n)>-1)return!1;e=e.replace(new RegExp("["+n+"]","gm"+t),"["+n+"]"),r.push(n)}return!0})}),e}},{key:"createMergedBlanksRegExp",value:function(e){return e.replace(/[\s]+/gim,"[\\s]+")}},{key:"createAccuracyRegExp",value:function(e){var t=this,n=this.opt.accuracy,r="string"==typeof n?n:n.value,i="";switch(("string"==typeof n?[]:n.limiters).forEach(function(e){i+="|"+t.escapeStr(e)}),r){case"partially":default:return"()("+e+")";case"complementary":return"()([^"+(i="\\s"+(i||this.escapeStr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~¡¿")))+"]*"+e+"[^"+i+"]*)";case"exactly":return"(^|\\s"+i+")("+e+")(?=$|\\s"+i+")"}}}]),e}(),a=function(){function a(e){t(this,a),this.ctx=e,this.ie=!1;var n=window.navigator.userAgent;(n.indexOf("MSIE")>-1||n.indexOf("Trident")>-1)&&(this.ie=!0)}return n(a,[{key:"log",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"debug",r=this.opt.log;this.opt.debug&&"object"===(void 0===r?"undefined":e(r))&&"function"==typeof r[n]&&r[n]("mark.js: "+t)}},{key:"getSeparatedKeywords",value:function(e){var t=this,n=[];return e.forEach(function(e){t.opt.separateWordSearch?e.split(" ").forEach(function(e){e.trim()&&-1===n.indexOf(e)&&n.push(e)}):e.trim()&&-1===n.indexOf(e)&&n.push(e)}),{keywords:n.sort(function(e,t){return t.length-e.length}),length:n.length}}},{key:"isNumeric",value:function(e){return Number(parseFloat(e))==e}},{key:"checkRanges",value:function(e){var t=this;if(!Array.isArray(e)||"[object Object]"!==Object.prototype.toString.call(e[0]))return this.log("markRanges() will only accept an array of objects"),this.opt.noMatch(e),[];var n=[],r=0;return e.sort(function(e,t){return e.start-t.start}).forEach(function(e){var i=t.callNoMatchOnInvalidRanges(e,r),o=i.start,a=i.end;i.valid&&(e.start=o,e.length=a-o,n.push(e),r=a)}),n}},{key:"callNoMatchOnInvalidRanges",value:function(e,t){var n=void 0,r=void 0,i=!1;return e&&void 0!==e.start?(r=(n=parseInt(e.start,10))+parseInt(e.length,10),this.isNumeric(e.start)&&this.isNumeric(e.length)&&r-t>0&&r-n>0?i=!0:(this.log("Ignoring invalid or overlapping range: "+JSON.stringify(e)),this.opt.noMatch(e))):(this.log("Ignoring invalid range: "+JSON.stringify(e)),this.opt.noMatch(e)),{start:n,end:r,valid:i}}},{key:"checkWhitespaceRanges",value:function(e,t,n){var r=void 0,i=!0,o=n.length,a=t-o,s=parseInt(e.start,10)-a;return(r=(s=s>o?o:s)+parseInt(e.length,10))>o&&(r=o,this.log("End range automatically set to the max value of "+o)),s<0||r-s<0||s>o||r>o?(i=!1,this.log("Invalid range: "+JSON.stringify(e)),this.opt.noMatch(e)):""===n.substring(s,r).replace(/\s+/g,"")&&(i=!1,this.log("Skipping whitespace only range: "+JSON.stringify(e)),this.opt.noMatch(e)),{start:s,end:r,valid:i}}},{key:"getTextNodes",value:function(e){var t=this,n="",r=[];this.iterator.forEachNode(NodeFilter.SHOW_TEXT,function(e){r.push({start:n.length,end:(n+=e.textContent).length,node:e})},function(e){return t.matchesExclude(e.parentNode)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},function(){e({value:n,nodes:r})})}},{key:"matchesExclude",value:function(e){return i.matches(e,this.opt.exclude.concat(["script","style","title","head","html"]))}},{key:"wrapRangeInTextNode",value:function(e,t,n){var r=this.opt.element?this.opt.element:"mark",i=e.splitText(t),o=i.splitText(n-t),a=document.createElement(r);return a.setAttribute("data-markjs","true"),this.opt.className&&a.setAttribute("class",this.opt.className),a.textContent=i.textContent,i.parentNode.replaceChild(a,i),o}},{key:"wrapRangeInMappedTextNode",value:function(e,t,n,r,i){var o=this;e.nodes.every(function(a,s){var c=e.nodes[s+1];if(void 0===c||c.start>t){if(!r(a.node))return!1;var u=t-a.start,l=(n>a.end?a.end:n)-a.start,h=e.value.substr(0,a.start),f=e.value.substr(l+a.start);if(a.node=o.wrapRangeInTextNode(a.node,u,l),e.value=h+f,e.nodes.forEach(function(t,n){n>=s&&(e.nodes[n].start>0&&n!==s&&(e.nodes[n].start-=l),e.nodes[n].end-=l)}),n-=l,i(a.node.previousSibling,a.start),!(n>a.end))return!1;t=a.end}return!0})}},{key:"wrapGroups",value:function(e,t,n,r){return r((e=this.wrapRangeInTextNode(e,t,t+n)).previousSibling),e}},{key:"separateGroups",value:function(e,t,n,r,i){for(var o=t.length,a=1;a-1&&r(t[a],e)&&(e=this.wrapGroups(e,s,t[a].length,i))}return e}},{key:"wrapMatches",value:function(e,t,n,r,i){var o=this,a=0===t?0:t+1;this.getTextNodes(function(t){t.nodes.forEach(function(t){t=t.node;for(var i=void 0;null!==(i=e.exec(t.textContent))&&""!==i[a];){if(o.opt.separateGroups)t=o.separateGroups(t,i,a,n,r);else{if(!n(i[a],t))continue;var s=i.index;if(0!==a)for(var c=1;c + + + + + Memory Management in Rustc - Rust Compiler Development Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

Memory Management in Rustc

+

Generally rustc tries to be pretty careful how it manages memory. +The compiler allocates a lot of data structures throughout compilation, +and if we are not careful, it will take a lot of time and space to do so.

+

One of the main way the compiler manages this is using arenas and interning.

+

Arenas and Interning

+

Since A LOT of data structures are created during compilation, for performance +reasons, we allocate them from a global memory pool. +Each are allocated once from a long-lived arena. +This is called arena allocation. +This system reduces allocations/deallocations of memory. +It also allows for easy comparison of types (more on types here) for equality: +for each interned type X, we implemented PartialEq for X, +so we can just compare pointers. +The CtxtInterners type contains a bunch of maps of interned types and the arena itself.

+

Example: ty::TyKind

+

Taking the example of ty::TyKind which represents a type in the compiler (you +can read more here). Each time we want to construct a type, the +compiler doesn’t naively allocate from the buffer. Instead, we check if that +type was already constructed. If it was, we just get the same pointer we had +before, otherwise we make a fresh pointer. With this schema if we want to know +if two types are the same, all we need to do is compare the pointers which is +efficient. ty::TyKind should never be constructed on the stack, and it would be unusable +if done so. +You always allocate them from this arena and you always intern them so they are +unique.

+

At the beginning of the compilation we make a buffer and each time we need to allocate a type we use +some of this memory buffer. If we run out of space we get another one. The lifetime of that buffer +is 'tcx. Our types are tied to that lifetime, so when compilation finishes all the memory related +to that buffer is freed and our 'tcx references would be invalid.

+

In addition to types, there are a number of other arena-allocated data structures that you can +allocate, and which are found in this module. Here are a few examples:

+
    +
  • GenericArgs, allocated with mk_args – this will intern a slice of types, often used +to specify the values to be substituted for generics args (e.g. HashMap<i32, u32> would be +represented as a slice &'tcx [tcx.types.i32, tcx.types.u32]).
  • +
  • TraitRef, typically passed by value – a trait reference consists of a reference to a trait +along with its various type parameters (including Self), like i32: Display (here, the def-id +would reference the Display trait, and the args would contain i32). Note that def-id is +defined and discussed in depth in the AdtDef and DefId section.
  • +
  • Predicate defines something the trait system has to prove (see traits module).
  • +
+

The tcx and how it uses lifetimes

+

The typing context (tcx) is the central data structure in the compiler. It is the context that +you use to perform all manner of queries. The struct TyCtxt defines a reference to this shared +context:

+
tcx: TyCtxt<'tcx>
+//          ----
+//          |
+//          arena lifetime
+
+

As you can see, the TyCtxt type takes a lifetime parameter. When you see a reference with a +lifetime like 'tcx, you know that it refers to arena-allocated data (or data that lives as long as +the arenas, anyhow).

+

A Note On Lifetimes

+

The Rust compiler is a fairly large program containing lots of big data +structures (e.g. the Abstract Syntax Tree (AST), High-Level Intermediate +Representation (HIR), and the type system) and as such, arenas and +references are heavily relied upon to minimize unnecessary memory use. This +manifests itself in the way people can plug into the compiler (i.e. the +driver), preferring a "push"-style API (callbacks) instead +of the more Rust-ic "pull" style (think the Iterator trait).

+

Thread-local storage and interning are used a lot through the compiler to reduce +duplication while also preventing a lot of the ergonomic issues due to many +pervasive lifetimes. The rustc_middle::ty::tls module is used to access these +thread-locals, although you should rarely need to touch it.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/mermaid-init.js b/mermaid-init.js new file mode 100644 index 000000000..313a6e8bc --- /dev/null +++ b/mermaid-init.js @@ -0,0 +1 @@ +mermaid.initialize({startOnLoad:true}); diff --git a/mermaid.min.js b/mermaid.min.js new file mode 100644 index 000000000..d45942f36 --- /dev/null +++ b/mermaid.min.js @@ -0,0 +1,4 @@ +/* MIT Licensed. Copyright (c) 2014 - 2021 Knut Sveidqvist */ +/*! For license information please see https://github.com/mermaid-js/mermaid/blob/8.13.10/LICENSE */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mermaid=e():t.mermaid=e()}("undefined"!=typeof self?self:this,(function(){return(()=>{var t={1362:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,6],n=[1,7],r=[1,8],i=[1,9],a=[1,12],o=[1,11],s=[1,15,24],c=[1,19],u=[1,31],l=[1,34],h=[1,32],f=[1,33],d=[1,35],p=[1,36],y=[1,37],g=[1,38],m=[1,41],v=[1,42],b=[1,43],_=[1,44],x=[15,24],w=[1,56],k=[1,57],T=[1,58],E=[1,59],C=[1,60],S=[1,61],A=[15,24,31,38,39,47,50,51,52,53,54,55,60,62],M=[15,24,29,31,38,39,43,47,50,51,52,53,54,55,60,62,77,78,79,80],N=[7,8,9,10,15,18,22,24],D=[47,77,78,79,80],O=[47,54,55,77,78,79,80],B=[47,50,51,52,53,77,78,79,80],L=[15,24,31],I=[1,93],R={trace:function(){},yy:{},symbols_:{error:2,start:3,mermaidDoc:4,direction:5,directive:6,direction_tb:7,direction_bt:8,direction_rl:9,direction_lr:10,graphConfig:11,openDirective:12,typeDirective:13,closeDirective:14,NEWLINE:15,":":16,argDirective:17,open_directive:18,type_directive:19,arg_directive:20,close_directive:21,CLASS_DIAGRAM:22,statements:23,EOF:24,statement:25,className:26,alphaNumToken:27,classLiteralName:28,GENERICTYPE:29,relationStatement:30,LABEL:31,classStatement:32,methodStatement:33,annotationStatement:34,clickStatement:35,cssClassStatement:36,CLASS:37,STYLE_SEPARATOR:38,STRUCT_START:39,members:40,STRUCT_STOP:41,ANNOTATION_START:42,ANNOTATION_END:43,MEMBER:44,SEPARATOR:45,relation:46,STR:47,relationType:48,lineType:49,AGGREGATION:50,EXTENSION:51,COMPOSITION:52,DEPENDENCY:53,LINE:54,DOTTED_LINE:55,CALLBACK:56,LINK:57,LINK_TARGET:58,CLICK:59,CALLBACK_NAME:60,CALLBACK_ARGS:61,HREF:62,CSSCLASS:63,commentToken:64,textToken:65,graphCodeTokens:66,textNoTagsToken:67,TAGSTART:68,TAGEND:69,"==":70,"--":71,PCT:72,DEFAULT:73,SPACE:74,MINUS:75,keywords:76,UNICODE_TEXT:77,NUM:78,ALPHA:79,BQUOTE_STR:80,$accept:0,$end:1},terminals_:{2:"error",7:"direction_tb",8:"direction_bt",9:"direction_rl",10:"direction_lr",15:"NEWLINE",16:":",18:"open_directive",19:"type_directive",20:"arg_directive",21:"close_directive",22:"CLASS_DIAGRAM",24:"EOF",29:"GENERICTYPE",31:"LABEL",37:"CLASS",38:"STYLE_SEPARATOR",39:"STRUCT_START",41:"STRUCT_STOP",42:"ANNOTATION_START",43:"ANNOTATION_END",44:"MEMBER",45:"SEPARATOR",47:"STR",50:"AGGREGATION",51:"EXTENSION",52:"COMPOSITION",53:"DEPENDENCY",54:"LINE",55:"DOTTED_LINE",56:"CALLBACK",57:"LINK",58:"LINK_TARGET",59:"CLICK",60:"CALLBACK_NAME",61:"CALLBACK_ARGS",62:"HREF",63:"CSSCLASS",66:"graphCodeTokens",68:"TAGSTART",69:"TAGEND",70:"==",71:"--",72:"PCT",73:"DEFAULT",74:"SPACE",75:"MINUS",76:"keywords",77:"UNICODE_TEXT",78:"NUM",79:"ALPHA",80:"BQUOTE_STR"},productions_:[0,[3,1],[3,1],[3,2],[5,1],[5,1],[5,1],[5,1],[4,1],[6,4],[6,6],[12,1],[13,1],[17,1],[14,1],[11,4],[23,1],[23,2],[23,3],[26,1],[26,1],[26,2],[26,2],[26,2],[25,1],[25,2],[25,1],[25,1],[25,1],[25,1],[25,1],[25,1],[25,1],[32,2],[32,4],[32,5],[32,7],[34,4],[40,1],[40,2],[33,1],[33,2],[33,1],[33,1],[30,3],[30,4],[30,4],[30,5],[46,3],[46,2],[46,2],[46,1],[48,1],[48,1],[48,1],[48,1],[49,1],[49,1],[35,3],[35,4],[35,3],[35,4],[35,4],[35,5],[35,3],[35,4],[35,4],[35,5],[35,3],[35,4],[35,4],[35,5],[36,3],[64,1],[64,1],[65,1],[65,1],[65,1],[65,1],[65,1],[65,1],[65,1],[67,1],[67,1],[67,1],[67,1],[27,1],[27,1],[27,1],[28,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 4:r.setDirection("TB");break;case 5:r.setDirection("BT");break;case 6:r.setDirection("RL");break;case 7:r.setDirection("LR");break;case 11:r.parseDirective("%%{","open_directive");break;case 12:r.parseDirective(a[s],"type_directive");break;case 13:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 14:r.parseDirective("}%%","close_directive","class");break;case 19:case 20:this.$=a[s];break;case 21:this.$=a[s-1]+a[s];break;case 22:case 23:this.$=a[s-1]+"~"+a[s];break;case 24:r.addRelation(a[s]);break;case 25:a[s-1].title=r.cleanupLabel(a[s]),r.addRelation(a[s-1]);break;case 33:r.addClass(a[s]);break;case 34:r.addClass(a[s-2]),r.setCssClass(a[s-2],a[s]);break;case 35:r.addClass(a[s-3]),r.addMembers(a[s-3],a[s-1]);break;case 36:r.addClass(a[s-5]),r.setCssClass(a[s-5],a[s-3]),r.addMembers(a[s-5],a[s-1]);break;case 37:r.addAnnotation(a[s],a[s-2]);break;case 38:this.$=[a[s]];break;case 39:a[s].push(a[s-1]),this.$=a[s];break;case 40:case 42:case 43:break;case 41:r.addMember(a[s-1],r.cleanupLabel(a[s]));break;case 44:this.$={id1:a[s-2],id2:a[s],relation:a[s-1],relationTitle1:"none",relationTitle2:"none"};break;case 45:this.$={id1:a[s-3],id2:a[s],relation:a[s-1],relationTitle1:a[s-2],relationTitle2:"none"};break;case 46:this.$={id1:a[s-3],id2:a[s],relation:a[s-2],relationTitle1:"none",relationTitle2:a[s-1]};break;case 47:this.$={id1:a[s-4],id2:a[s],relation:a[s-2],relationTitle1:a[s-3],relationTitle2:a[s-1]};break;case 48:this.$={type1:a[s-2],type2:a[s],lineType:a[s-1]};break;case 49:this.$={type1:"none",type2:a[s],lineType:a[s-1]};break;case 50:this.$={type1:a[s-1],type2:"none",lineType:a[s]};break;case 51:this.$={type1:"none",type2:"none",lineType:a[s]};break;case 52:this.$=r.relationType.AGGREGATION;break;case 53:this.$=r.relationType.EXTENSION;break;case 54:this.$=r.relationType.COMPOSITION;break;case 55:this.$=r.relationType.DEPENDENCY;break;case 56:this.$=r.lineType.LINE;break;case 57:this.$=r.lineType.DOTTED_LINE;break;case 58:case 64:this.$=a[s-2],r.setClickEvent(a[s-1],a[s]);break;case 59:case 65:this.$=a[s-3],r.setClickEvent(a[s-2],a[s-1]),r.setTooltip(a[s-2],a[s]);break;case 60:case 68:this.$=a[s-2],r.setLink(a[s-1],a[s]);break;case 61:case 69:this.$=a[s-3],r.setLink(a[s-2],a[s-1],a[s]);break;case 62:case 70:this.$=a[s-3],r.setLink(a[s-2],a[s-1]),r.setTooltip(a[s-2],a[s]);break;case 63:case 71:this.$=a[s-4],r.setLink(a[s-3],a[s-2],a[s]),r.setTooltip(a[s-3],a[s-1]);break;case 66:this.$=a[s-3],r.setClickEvent(a[s-2],a[s-1],a[s]);break;case 67:this.$=a[s-4],r.setClickEvent(a[s-3],a[s-2],a[s-1]),r.setTooltip(a[s-3],a[s]);break;case 72:r.setCssClass(a[s-1],a[s])}},table:[{3:1,4:2,5:3,6:4,7:e,8:n,9:r,10:i,11:5,12:10,18:a,22:o},{1:[3]},{1:[2,1]},{1:[2,2]},{3:13,4:2,5:3,6:4,7:e,8:n,9:r,10:i,11:5,12:10,18:a,22:o},{1:[2,8]},t(s,[2,4]),t(s,[2,5]),t(s,[2,6]),t(s,[2,7]),{13:14,19:[1,15]},{15:[1,16]},{19:[2,11]},{1:[2,3]},{14:17,16:[1,18],21:c},t([16,21],[2,12]),{5:29,6:28,7:e,8:n,9:r,10:i,12:10,18:a,23:20,25:21,26:30,27:39,28:40,30:22,32:23,33:24,34:25,35:26,36:27,37:u,42:l,44:h,45:f,56:d,57:p,59:y,63:g,77:m,78:v,79:b,80:_},{15:[1,45]},{17:46,20:[1,47]},{15:[2,14]},{24:[1,48]},{15:[1,49],24:[2,16]},t(x,[2,24],{31:[1,50]}),t(x,[2,26]),t(x,[2,27]),t(x,[2,28]),t(x,[2,29]),t(x,[2,30]),t(x,[2,31]),t(x,[2,32]),t(x,[2,40],{46:51,48:54,49:55,31:[1,53],47:[1,52],50:w,51:k,52:T,53:E,54:C,55:S}),{26:62,27:39,28:40,77:m,78:v,79:b,80:_},t(x,[2,42]),t(x,[2,43]),{27:63,77:m,78:v,79:b},{26:64,27:39,28:40,77:m,78:v,79:b,80:_},{26:65,27:39,28:40,77:m,78:v,79:b,80:_},{26:66,27:39,28:40,77:m,78:v,79:b,80:_},{47:[1,67]},t(A,[2,19],{27:39,28:40,26:68,29:[1,69],77:m,78:v,79:b,80:_}),t(A,[2,20],{29:[1,70]}),t(M,[2,86]),t(M,[2,87]),t(M,[2,88]),t([15,24,29,31,38,39,47,50,51,52,53,54,55,60,62],[2,89]),t(N,[2,9]),{14:71,21:c},{21:[2,13]},{1:[2,15]},{5:29,6:28,7:e,8:n,9:r,10:i,12:10,18:a,23:72,24:[2,17],25:21,26:30,27:39,28:40,30:22,32:23,33:24,34:25,35:26,36:27,37:u,42:l,44:h,45:f,56:d,57:p,59:y,63:g,77:m,78:v,79:b,80:_},t(x,[2,25]),{26:73,27:39,28:40,47:[1,74],77:m,78:v,79:b,80:_},{46:75,48:54,49:55,50:w,51:k,52:T,53:E,54:C,55:S},t(x,[2,41]),{49:76,54:C,55:S},t(D,[2,51],{48:77,50:w,51:k,52:T,53:E}),t(O,[2,52]),t(O,[2,53]),t(O,[2,54]),t(O,[2,55]),t(B,[2,56]),t(B,[2,57]),t(x,[2,33],{38:[1,78],39:[1,79]}),{43:[1,80]},{47:[1,81]},{47:[1,82]},{60:[1,83],62:[1,84]},{27:85,77:m,78:v,79:b},t(A,[2,21]),t(A,[2,22]),t(A,[2,23]),{15:[1,86]},{24:[2,18]},t(L,[2,44]),{26:87,27:39,28:40,77:m,78:v,79:b,80:_},{26:88,27:39,28:40,47:[1,89],77:m,78:v,79:b,80:_},t(D,[2,50],{48:90,50:w,51:k,52:T,53:E}),t(D,[2,49]),{27:91,77:m,78:v,79:b},{40:92,44:I},{26:94,27:39,28:40,77:m,78:v,79:b,80:_},t(x,[2,58],{47:[1,95]}),t(x,[2,60],{47:[1,97],58:[1,96]}),t(x,[2,64],{47:[1,98],61:[1,99]}),t(x,[2,68],{47:[1,101],58:[1,100]}),t(x,[2,72]),t(N,[2,10]),t(L,[2,46]),t(L,[2,45]),{26:102,27:39,28:40,77:m,78:v,79:b,80:_},t(D,[2,48]),t(x,[2,34],{39:[1,103]}),{41:[1,104]},{40:105,41:[2,38],44:I},t(x,[2,37]),t(x,[2,59]),t(x,[2,61]),t(x,[2,62],{58:[1,106]}),t(x,[2,65]),t(x,[2,66],{47:[1,107]}),t(x,[2,69]),t(x,[2,70],{58:[1,108]}),t(L,[2,47]),{40:109,44:I},t(x,[2,35]),{41:[2,39]},t(x,[2,63]),t(x,[2,67]),t(x,[2,71]),{41:[1,110]},t(x,[2,36])],defaultActions:{2:[2,1],3:[2,2],5:[2,8],12:[2,11],13:[2,3],19:[2,14],47:[2,13],48:[2,15],72:[2,18],105:[2,39]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},F={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),18;case 1:return 7;case 2:return 8;case 3:return 9;case 4:return 10;case 5:return this.begin("type_directive"),19;case 6:return this.popState(),this.begin("arg_directive"),16;case 7:return this.popState(),this.popState(),21;case 8:return 20;case 9:case 10:case 12:case 19:break;case 11:return 15;case 13:case 14:return 22;case 15:return this.begin("struct"),39;case 16:return"EOF_IN_STRUCT";case 17:return"OPEN_IN_STRUCT";case 18:return this.popState(),41;case 20:return"MEMBER";case 21:return 37;case 22:return 63;case 23:return 56;case 24:return 57;case 25:return 59;case 26:return 42;case 27:return 43;case 28:this.begin("generic");break;case 29:case 32:case 35:case 38:case 41:case 44:this.popState();break;case 30:return"GENERICTYPE";case 31:this.begin("string");break;case 33:return"STR";case 34:this.begin("bqstring");break;case 36:return"BQUOTE_STR";case 37:this.begin("href");break;case 39:return 62;case 40:this.begin("callback_name");break;case 42:this.popState(),this.begin("callback_args");break;case 43:return 60;case 45:return 61;case 46:case 47:case 48:case 49:return 58;case 50:case 51:return 51;case 52:case 53:return 53;case 54:return 52;case 55:return 50;case 56:return 54;case 57:return 55;case 58:return 31;case 59:return 38;case 60:return 75;case 61:return"DOT";case 62:return"PLUS";case 63:return 72;case 64:case 65:return"EQUALS";case 66:return 79;case 67:return"PUNCTUATION";case 68:return 78;case 69:return 77;case 70:return 74;case 71:return 24}},rules:[/^(?:%%\{)/,/^(?:.*direction\s+TB[^\n]*)/,/^(?:.*direction\s+BT[^\n]*)/,/^(?:.*direction\s+RL[^\n]*)/,/^(?:.*direction\s+LR[^\n]*)/,/^(?:((?:(?!\}%%)[^:.])*))/,/^(?::)/,/^(?:\}%%)/,/^(?:((?:(?!\}%%).|\n)*))/,/^(?:%%(?!\{)*[^\n]*(\r?\n?)+)/,/^(?:%%[^\n]*(\r?\n)*)/,/^(?:\s*(\r?\n)+)/,/^(?:\s+)/,/^(?:classDiagram-v2\b)/,/^(?:classDiagram\b)/,/^(?:[{])/,/^(?:$)/,/^(?:[{])/,/^(?:[}])/,/^(?:[\n])/,/^(?:[^{}\n]*)/,/^(?:class\b)/,/^(?:cssClass\b)/,/^(?:callback\b)/,/^(?:link\b)/,/^(?:click\b)/,/^(?:<<)/,/^(?:>>)/,/^(?:[~])/,/^(?:[~])/,/^(?:[^~]*)/,/^(?:["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:[`])/,/^(?:[`])/,/^(?:[^`]+)/,/^(?:href[\s]+["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:call[\s]+)/,/^(?:\([\s]*\))/,/^(?:\()/,/^(?:[^(]*)/,/^(?:\))/,/^(?:[^)]*)/,/^(?:_self\b)/,/^(?:_blank\b)/,/^(?:_parent\b)/,/^(?:_top\b)/,/^(?:\s*<\|)/,/^(?:\s*\|>)/,/^(?:\s*>)/,/^(?:\s*<)/,/^(?:\s*\*)/,/^(?:\s*o\b)/,/^(?:--)/,/^(?:\.\.)/,/^(?::{1}[^:\n;]+)/,/^(?::{3})/,/^(?:-)/,/^(?:\.)/,/^(?:\+)/,/^(?:%)/,/^(?:=)/,/^(?:=)/,/^(?:\w+)/,/^(?:[!"#$%&'*+,-.`?\\/])/,/^(?:[0-9]+)/,/^(?:[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|[\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE]|[\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA]|[\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0]|[\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977]|[\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2]|[\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A]|[\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39]|[\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8]|[\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C]|[\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C]|[\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99]|[\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0]|[\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D]|[\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3]|[\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10]|[\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1]|[\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81]|[\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3]|[\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6]|[\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A]|[\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081]|[\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D]|[\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0]|[\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310]|[\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C]|[\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711]|[\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7]|[\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C]|[\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16]|[\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF]|[\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC]|[\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D]|[\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D]|[\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3]|[\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F]|[\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128]|[\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184]|[\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3]|[\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6]|[\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE]|[\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C]|[\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D]|[\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC]|[\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B]|[\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788]|[\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805]|[\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB]|[\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28]|[\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5]|[\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4]|[\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E]|[\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D]|[\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36]|[\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D]|[\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]|[\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF]|[\uFFD2-\uFFD7\uFFDA-\uFFDC])/,/^(?:\s)/,/^(?:$)/],conditions:{arg_directive:{rules:[7,8],inclusive:!1},type_directive:{rules:[6,7],inclusive:!1},open_directive:{rules:[5],inclusive:!1},callback_args:{rules:[44,45],inclusive:!1},callback_name:{rules:[41,42,43],inclusive:!1},href:{rules:[38,39],inclusive:!1},struct:{rules:[16,17,18,19,20],inclusive:!1},generic:{rules:[29,30],inclusive:!1},bqstring:{rules:[35,36],inclusive:!1},string:{rules:[32,33],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,9,10,11,12,13,14,15,21,22,23,24,25,26,27,28,31,34,37,40,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71],inclusive:!0}}};function P(){this.yy={}}return R.lexer=F,P.prototype=R,R.Parser=P,new P}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(8218).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},5890:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,2],n=[1,5],r=[6,9,11,23,41],i=[1,17],a=[1,20],o=[1,25],s=[1,26],c=[1,27],u=[1,28],l=[1,37],h=[23,38,39],f=[4,6,9,11,23,41],d=[34,35,36,37],p=[22,29],y=[1,55],g={trace:function(){},yy:{},symbols_:{error:2,start:3,ER_DIAGRAM:4,document:5,EOF:6,directive:7,line:8,SPACE:9,statement:10,NEWLINE:11,openDirective:12,typeDirective:13,closeDirective:14,":":15,argDirective:16,entityName:17,relSpec:18,role:19,BLOCK_START:20,attributes:21,BLOCK_STOP:22,ALPHANUM:23,attribute:24,attributeType:25,attributeName:26,attributeKeyType:27,attributeComment:28,ATTRIBUTE_WORD:29,ATTRIBUTE_KEY:30,COMMENT:31,cardinality:32,relType:33,ZERO_OR_ONE:34,ZERO_OR_MORE:35,ONE_OR_MORE:36,ONLY_ONE:37,NON_IDENTIFYING:38,IDENTIFYING:39,WORD:40,open_directive:41,type_directive:42,arg_directive:43,close_directive:44,$accept:0,$end:1},terminals_:{2:"error",4:"ER_DIAGRAM",6:"EOF",9:"SPACE",11:"NEWLINE",15:":",20:"BLOCK_START",22:"BLOCK_STOP",23:"ALPHANUM",29:"ATTRIBUTE_WORD",30:"ATTRIBUTE_KEY",31:"COMMENT",34:"ZERO_OR_ONE",35:"ZERO_OR_MORE",36:"ONE_OR_MORE",37:"ONLY_ONE",38:"NON_IDENTIFYING",39:"IDENTIFYING",40:"WORD",41:"open_directive",42:"type_directive",43:"arg_directive",44:"close_directive"},productions_:[0,[3,3],[3,2],[5,0],[5,2],[8,2],[8,1],[8,1],[8,1],[7,4],[7,6],[10,1],[10,5],[10,4],[10,3],[10,1],[17,1],[21,1],[21,2],[24,2],[24,3],[24,3],[24,4],[25,1],[26,1],[27,1],[28,1],[18,3],[32,1],[32,1],[32,1],[32,1],[33,1],[33,1],[19,1],[19,1],[12,1],[13,1],[16,1],[14,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 1:break;case 3:case 7:case 8:this.$=[];break;case 4:a[s-1].push(a[s]),this.$=a[s-1];break;case 5:case 6:case 16:case 23:case 24:case 25:case 35:this.$=a[s];break;case 12:r.addEntity(a[s-4]),r.addEntity(a[s-2]),r.addRelationship(a[s-4],a[s],a[s-2],a[s-3]);break;case 13:r.addEntity(a[s-3]),r.addAttributes(a[s-3],a[s-1]);break;case 14:r.addEntity(a[s-2]);break;case 15:r.addEntity(a[s]);break;case 17:this.$=[a[s]];break;case 18:a[s].push(a[s-1]),this.$=a[s];break;case 19:this.$={attributeType:a[s-1],attributeName:a[s]};break;case 20:this.$={attributeType:a[s-2],attributeName:a[s-1],attributeKeyType:a[s]};break;case 21:this.$={attributeType:a[s-2],attributeName:a[s-1],attributeComment:a[s]};break;case 22:this.$={attributeType:a[s-3],attributeName:a[s-2],attributeKeyType:a[s-1],attributeComment:a[s]};break;case 26:case 34:this.$=a[s].replace(/"/g,"");break;case 27:this.$={cardA:a[s],relType:a[s-1],cardB:a[s-2]};break;case 28:this.$=r.Cardinality.ZERO_OR_ONE;break;case 29:this.$=r.Cardinality.ZERO_OR_MORE;break;case 30:this.$=r.Cardinality.ONE_OR_MORE;break;case 31:this.$=r.Cardinality.ONLY_ONE;break;case 32:this.$=r.Identification.NON_IDENTIFYING;break;case 33:this.$=r.Identification.IDENTIFYING;break;case 36:r.parseDirective("%%{","open_directive");break;case 37:r.parseDirective(a[s],"type_directive");break;case 38:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 39:r.parseDirective("}%%","close_directive","er")}},table:[{3:1,4:e,7:3,12:4,41:n},{1:[3]},t(r,[2,3],{5:6}),{3:7,4:e,7:3,12:4,41:n},{13:8,42:[1,9]},{42:[2,36]},{6:[1,10],7:15,8:11,9:[1,12],10:13,11:[1,14],12:4,17:16,23:i,41:n},{1:[2,2]},{14:18,15:[1,19],44:a},t([15,44],[2,37]),t(r,[2,8],{1:[2,1]}),t(r,[2,4]),{7:15,10:21,12:4,17:16,23:i,41:n},t(r,[2,6]),t(r,[2,7]),t(r,[2,11]),t(r,[2,15],{18:22,32:24,20:[1,23],34:o,35:s,36:c,37:u}),t([6,9,11,15,20,23,34,35,36,37,41],[2,16]),{11:[1,29]},{16:30,43:[1,31]},{11:[2,39]},t(r,[2,5]),{17:32,23:i},{21:33,22:[1,34],24:35,25:36,29:l},{33:38,38:[1,39],39:[1,40]},t(h,[2,28]),t(h,[2,29]),t(h,[2,30]),t(h,[2,31]),t(f,[2,9]),{14:41,44:a},{44:[2,38]},{15:[1,42]},{22:[1,43]},t(r,[2,14]),{21:44,22:[2,17],24:35,25:36,29:l},{26:45,29:[1,46]},{29:[2,23]},{32:47,34:o,35:s,36:c,37:u},t(d,[2,32]),t(d,[2,33]),{11:[1,48]},{19:49,23:[1,51],40:[1,50]},t(r,[2,13]),{22:[2,18]},t(p,[2,19],{27:52,28:53,30:[1,54],31:y}),t([22,29,30,31],[2,24]),{23:[2,27]},t(f,[2,10]),t(r,[2,12]),t(r,[2,34]),t(r,[2,35]),t(p,[2,20],{28:56,31:y}),t(p,[2,21]),t([22,29,31],[2,25]),t(p,[2,26]),t(p,[2,22])],defaultActions:{5:[2,36],7:[2,2],20:[2,39],31:[2,38],37:[2,23],44:[2,18],47:[2,27]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},m={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),41;case 1:return this.begin("type_directive"),42;case 2:return this.popState(),this.begin("arg_directive"),15;case 3:return this.popState(),this.popState(),44;case 4:return 43;case 5:case 6:case 8:case 13:case 17:break;case 7:return 11;case 9:return 9;case 10:return 40;case 11:return 4;case 12:return this.begin("block"),20;case 14:return 30;case 15:return 29;case 16:return 31;case 18:return this.popState(),22;case 19:case 32:return e.yytext[0];case 20:case 24:return 34;case 21:case 25:return 35;case 22:case 26:return 36;case 23:return 37;case 27:case 29:case 30:return 38;case 28:return 39;case 31:return 23;case 33:return 6}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:[\s]+)/i,/^(?:"[^"]*")/i,/^(?:erDiagram\b)/i,/^(?:\{)/i,/^(?:\s+)/i,/^(?:(?:PK)|(?:FK))/i,/^(?:[A-Za-z][A-Za-z0-9\-_]*)/i,/^(?:"[^"]*")/i,/^(?:[\n]+)/i,/^(?:\})/i,/^(?:.)/i,/^(?:\|o\b)/i,/^(?:\}o\b)/i,/^(?:\}\|)/i,/^(?:\|\|)/i,/^(?:o\|)/i,/^(?:o\{)/i,/^(?:\|\{)/i,/^(?:\.\.)/i,/^(?:--)/i,/^(?:\.-)/i,/^(?:-\.)/i,/^(?:[A-Za-z][A-Za-z0-9\-_]*)/i,/^(?:.)/i,/^(?:$)/i],conditions:{open_directive:{rules:[1],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},block:{rules:[13,14,15,16,17,18,19],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,11,12,20,21,22,23,24,25,26,27,28,29,30,31,32,33],inclusive:!0}}};function v(){this.yy={}}return g.lexer=m,v.prototype=g,g.Parser=v,new v}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(8009).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},3602:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,9],n=[1,7],r=[1,6],i=[1,8],a=[1,20,21,22,23,38,47,59,60,79,80,81,82,83,84,88,98,99,102,104,105,111,112,113,114,115,116,117,118,119,120],o=[2,10],s=[1,20],c=[1,21],u=[1,22],l=[1,23],h=[1,30],f=[1,59],d=[1,45],p=[1,49],y=[1,33],g=[1,34],m=[1,35],v=[1,36],b=[1,37],_=[1,53],x=[1,60],w=[1,48],k=[1,50],T=[1,52],E=[1,56],C=[1,57],S=[1,38],A=[1,39],M=[1,40],N=[1,41],D=[1,58],O=[1,47],B=[1,51],L=[1,54],I=[1,55],R=[1,46],F=[1,63],P=[1,68],j=[1,20,21,22,23,38,42,47,59,60,79,80,81,82,83,84,88,98,99,102,104,105,111,112,113,114,115,116,117,118,119,120],Y=[1,72],z=[1,71],U=[1,73],q=[20,21,23,74,75],H=[1,94],$=[1,99],W=[1,102],V=[1,103],G=[1,96],X=[1,101],Z=[1,104],Q=[1,97],K=[1,109],J=[1,108],tt=[1,98],et=[1,100],nt=[1,105],rt=[1,106],it=[1,107],at=[1,110],ot=[20,21,22,23,74,75],st=[20,21,22,23,48,74,75],ct=[20,21,22,23,40,47,48,50,52,54,56,58,59,60,62,64,66,67,69,74,75,84,88,98,99,102,104,105,115,116,117,118,119,120],ut=[20,21,23],lt=[20,21,23,47,59,60,74,75,84,88,98,99,102,104,105,115,116,117,118,119,120],ht=[1,12,20,21,22,23,24,38,42,47,59,60,79,80,81,82,83,84,88,98,99,102,104,105,111,112,113,114,115,116,117,118,119,120],ft=[47,59,60,84,88,98,99,102,104,105,115,116,117,118,119,120],dt=[1,143],pt=[1,151],yt=[1,152],gt=[1,153],mt=[1,154],vt=[1,138],bt=[1,139],_t=[1,135],xt=[1,146],wt=[1,147],kt=[1,148],Tt=[1,149],Et=[1,150],Ct=[1,155],St=[1,156],At=[1,141],Mt=[1,144],Nt=[1,140],Dt=[1,137],Ot=[20,21,22,23,38,42,47,59,60,79,80,81,82,83,84,88,98,99,102,104,105,111,112,113,114,115,116,117,118,119,120],Bt=[1,159],Lt=[20,21,22,23,26,47,59,60,84,98,99,102,104,105,115,116,117,118,119,120],It=[20,21,22,23,24,26,38,40,41,42,47,51,53,55,57,59,60,61,63,65,66,68,70,74,75,79,80,81,82,83,84,85,88,98,99,102,104,105,106,107,115,116,117,118,119,120],Rt=[12,21,22,24],Ft=[22,99],Pt=[1,242],jt=[1,237],Yt=[1,238],zt=[1,246],Ut=[1,243],qt=[1,240],Ht=[1,239],$t=[1,241],Wt=[1,244],Vt=[1,245],Gt=[1,247],Xt=[1,265],Zt=[20,21,23,99],Qt=[20,21,22,23,59,60,79,95,98,99,102,103,104,105,106],Kt={trace:function(){},yy:{},symbols_:{error:2,start:3,mermaidDoc:4,directive:5,openDirective:6,typeDirective:7,closeDirective:8,separator:9,":":10,argDirective:11,open_directive:12,type_directive:13,arg_directive:14,close_directive:15,graphConfig:16,document:17,line:18,statement:19,SEMI:20,NEWLINE:21,SPACE:22,EOF:23,GRAPH:24,NODIR:25,DIR:26,FirstStmtSeperator:27,ending:28,endToken:29,spaceList:30,spaceListNewline:31,verticeStatement:32,styleStatement:33,linkStyleStatement:34,classDefStatement:35,classStatement:36,clickStatement:37,subgraph:38,text:39,SQS:40,SQE:41,end:42,direction:43,link:44,node:45,vertex:46,AMP:47,STYLE_SEPARATOR:48,idString:49,PS:50,PE:51,"(-":52,"-)":53,STADIUMSTART:54,STADIUMEND:55,SUBROUTINESTART:56,SUBROUTINEEND:57,VERTEX_WITH_PROPS_START:58,ALPHA:59,COLON:60,PIPE:61,CYLINDERSTART:62,CYLINDEREND:63,DIAMOND_START:64,DIAMOND_STOP:65,TAGEND:66,TRAPSTART:67,TRAPEND:68,INVTRAPSTART:69,INVTRAPEND:70,linkStatement:71,arrowText:72,TESTSTR:73,START_LINK:74,LINK:75,textToken:76,STR:77,keywords:78,STYLE:79,LINKSTYLE:80,CLASSDEF:81,CLASS:82,CLICK:83,DOWN:84,UP:85,textNoTags:86,textNoTagsToken:87,DEFAULT:88,stylesOpt:89,alphaNum:90,CALLBACKNAME:91,CALLBACKARGS:92,HREF:93,LINK_TARGET:94,HEX:95,numList:96,INTERPOLATE:97,NUM:98,COMMA:99,style:100,styleComponent:101,MINUS:102,UNIT:103,BRKT:104,DOT:105,PCT:106,TAGSTART:107,alphaNumToken:108,idStringToken:109,alphaNumStatement:110,direction_tb:111,direction_bt:112,direction_rl:113,direction_lr:114,PUNCTUATION:115,UNICODE_TEXT:116,PLUS:117,EQUALS:118,MULT:119,UNDERSCORE:120,graphCodeTokens:121,ARROW_CROSS:122,ARROW_POINT:123,ARROW_CIRCLE:124,ARROW_OPEN:125,QUOTE:126,$accept:0,$end:1},terminals_:{2:"error",10:":",12:"open_directive",13:"type_directive",14:"arg_directive",15:"close_directive",20:"SEMI",21:"NEWLINE",22:"SPACE",23:"EOF",24:"GRAPH",25:"NODIR",26:"DIR",38:"subgraph",40:"SQS",41:"SQE",42:"end",47:"AMP",48:"STYLE_SEPARATOR",50:"PS",51:"PE",52:"(-",53:"-)",54:"STADIUMSTART",55:"STADIUMEND",56:"SUBROUTINESTART",57:"SUBROUTINEEND",58:"VERTEX_WITH_PROPS_START",59:"ALPHA",60:"COLON",61:"PIPE",62:"CYLINDERSTART",63:"CYLINDEREND",64:"DIAMOND_START",65:"DIAMOND_STOP",66:"TAGEND",67:"TRAPSTART",68:"TRAPEND",69:"INVTRAPSTART",70:"INVTRAPEND",73:"TESTSTR",74:"START_LINK",75:"LINK",77:"STR",79:"STYLE",80:"LINKSTYLE",81:"CLASSDEF",82:"CLASS",83:"CLICK",84:"DOWN",85:"UP",88:"DEFAULT",91:"CALLBACKNAME",92:"CALLBACKARGS",93:"HREF",94:"LINK_TARGET",95:"HEX",97:"INTERPOLATE",98:"NUM",99:"COMMA",102:"MINUS",103:"UNIT",104:"BRKT",105:"DOT",106:"PCT",107:"TAGSTART",111:"direction_tb",112:"direction_bt",113:"direction_rl",114:"direction_lr",115:"PUNCTUATION",116:"UNICODE_TEXT",117:"PLUS",118:"EQUALS",119:"MULT",120:"UNDERSCORE",122:"ARROW_CROSS",123:"ARROW_POINT",124:"ARROW_CIRCLE",125:"ARROW_OPEN",126:"QUOTE"},productions_:[0,[3,1],[3,2],[5,4],[5,6],[6,1],[7,1],[11,1],[8,1],[4,2],[17,0],[17,2],[18,1],[18,1],[18,1],[18,1],[18,1],[16,2],[16,2],[16,2],[16,3],[28,2],[28,1],[29,1],[29,1],[29,1],[27,1],[27,1],[27,2],[31,2],[31,2],[31,1],[31,1],[30,2],[30,1],[19,2],[19,2],[19,2],[19,2],[19,2],[19,2],[19,9],[19,6],[19,4],[19,1],[9,1],[9,1],[9,1],[32,3],[32,4],[32,2],[32,1],[45,1],[45,5],[45,3],[46,4],[46,6],[46,4],[46,4],[46,4],[46,8],[46,4],[46,4],[46,4],[46,6],[46,4],[46,4],[46,4],[46,4],[46,4],[46,1],[44,2],[44,3],[44,3],[44,1],[44,3],[71,1],[72,3],[39,1],[39,2],[39,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[86,1],[86,2],[35,5],[35,5],[36,5],[37,2],[37,4],[37,3],[37,5],[37,2],[37,4],[37,4],[37,6],[37,2],[37,4],[37,2],[37,4],[37,4],[37,6],[33,5],[33,5],[34,5],[34,5],[34,9],[34,9],[34,7],[34,7],[96,1],[96,3],[89,1],[89,3],[100,1],[100,2],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[76,1],[76,1],[76,1],[76,1],[76,1],[76,1],[87,1],[87,1],[87,1],[87,1],[49,1],[49,2],[90,1],[90,2],[110,1],[110,1],[110,1],[110,1],[43,1],[43,1],[43,1],[43,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 5:r.parseDirective("%%{","open_directive");break;case 6:r.parseDirective(a[s],"type_directive");break;case 7:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 8:r.parseDirective("}%%","close_directive","flowchart");break;case 10:case 36:case 37:case 38:case 39:case 40:this.$=[];break;case 11:a[s]!==[]&&a[s-1].push(a[s]),this.$=a[s-1];break;case 12:case 78:case 80:case 92:case 148:case 150:case 151:case 74:case 146:this.$=a[s];break;case 19:r.setDirection("TB"),this.$="TB";break;case 20:r.setDirection(a[s-1]),this.$=a[s-1];break;case 35:this.$=a[s-1].nodes;break;case 41:this.$=r.addSubGraph(a[s-6],a[s-1],a[s-4]);break;case 42:this.$=r.addSubGraph(a[s-3],a[s-1],a[s-3]);break;case 43:this.$=r.addSubGraph(void 0,a[s-1],void 0);break;case 48:r.addLink(a[s-2].stmt,a[s],a[s-1]),this.$={stmt:a[s],nodes:a[s].concat(a[s-2].nodes)};break;case 49:r.addLink(a[s-3].stmt,a[s-1],a[s-2]),this.$={stmt:a[s-1],nodes:a[s-1].concat(a[s-3].nodes)};break;case 50:this.$={stmt:a[s-1],nodes:a[s-1]};break;case 51:this.$={stmt:a[s],nodes:a[s]};break;case 52:case 119:case 121:this.$=[a[s]];break;case 53:this.$=a[s-4].concat(a[s]);break;case 54:this.$=[a[s-2]],r.setClass(a[s-2],a[s]);break;case 55:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"square");break;case 56:this.$=a[s-5],r.addVertex(a[s-5],a[s-2],"circle");break;case 57:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"ellipse");break;case 58:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"stadium");break;case 59:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"subroutine");break;case 60:this.$=a[s-7],r.addVertex(a[s-7],a[s-1],"rect",void 0,void 0,void 0,Object.fromEntries([[a[s-5],a[s-3]]]));break;case 61:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"cylinder");break;case 62:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"round");break;case 63:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"diamond");break;case 64:this.$=a[s-5],r.addVertex(a[s-5],a[s-2],"hexagon");break;case 65:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"odd");break;case 66:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"trapezoid");break;case 67:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"inv_trapezoid");break;case 68:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"lean_right");break;case 69:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"lean_left");break;case 70:this.$=a[s],r.addVertex(a[s]);break;case 71:a[s-1].text=a[s],this.$=a[s-1];break;case 72:case 73:a[s-2].text=a[s-1],this.$=a[s-2];break;case 75:var c=r.destructLink(a[s],a[s-2]);this.$={type:c.type,stroke:c.stroke,length:c.length,text:a[s-1]};break;case 76:c=r.destructLink(a[s]),this.$={type:c.type,stroke:c.stroke,length:c.length};break;case 77:this.$=a[s-1];break;case 79:case 93:case 149:case 147:this.$=a[s-1]+""+a[s];break;case 94:case 95:this.$=a[s-4],r.addClass(a[s-2],a[s]);break;case 96:this.$=a[s-4],r.setClass(a[s-2],a[s]);break;case 97:case 105:this.$=a[s-1],r.setClickEvent(a[s-1],a[s]);break;case 98:case 106:this.$=a[s-3],r.setClickEvent(a[s-3],a[s-2]),r.setTooltip(a[s-3],a[s]);break;case 99:this.$=a[s-2],r.setClickEvent(a[s-2],a[s-1],a[s]);break;case 100:this.$=a[s-4],r.setClickEvent(a[s-4],a[s-3],a[s-2]),r.setTooltip(a[s-4],a[s]);break;case 101:case 107:this.$=a[s-1],r.setLink(a[s-1],a[s]);break;case 102:case 108:this.$=a[s-3],r.setLink(a[s-3],a[s-2]),r.setTooltip(a[s-3],a[s]);break;case 103:case 109:this.$=a[s-3],r.setLink(a[s-3],a[s-2],a[s]);break;case 104:case 110:this.$=a[s-5],r.setLink(a[s-5],a[s-4],a[s]),r.setTooltip(a[s-5],a[s-2]);break;case 111:this.$=a[s-4],r.addVertex(a[s-2],void 0,void 0,a[s]);break;case 112:case 114:this.$=a[s-4],r.updateLink(a[s-2],a[s]);break;case 113:this.$=a[s-4],r.updateLink([a[s-2]],a[s]);break;case 115:this.$=a[s-8],r.updateLinkInterpolate([a[s-6]],a[s-2]),r.updateLink([a[s-6]],a[s]);break;case 116:this.$=a[s-8],r.updateLinkInterpolate(a[s-6],a[s-2]),r.updateLink(a[s-6],a[s]);break;case 117:this.$=a[s-6],r.updateLinkInterpolate([a[s-4]],a[s]);break;case 118:this.$=a[s-6],r.updateLinkInterpolate(a[s-4],a[s]);break;case 120:case 122:a[s-2].push(a[s]),this.$=a[s-2];break;case 124:this.$=a[s-1]+a[s];break;case 152:this.$="v";break;case 153:this.$="-";break;case 154:this.$={stmt:"dir",value:"TB"};break;case 155:this.$={stmt:"dir",value:"BT"};break;case 156:this.$={stmt:"dir",value:"RL"};break;case 157:this.$={stmt:"dir",value:"LR"}}},table:[{3:1,4:2,5:3,6:5,12:e,16:4,21:n,22:r,24:i},{1:[3]},{1:[2,1]},{3:10,4:2,5:3,6:5,12:e,16:4,21:n,22:r,24:i},t(a,o,{17:11}),{7:12,13:[1,13]},{16:14,21:n,22:r,24:i},{16:15,21:n,22:r,24:i},{25:[1,16],26:[1,17]},{13:[2,5]},{1:[2,2]},{1:[2,9],18:18,19:19,20:s,21:c,22:u,23:l,32:24,33:25,34:26,35:27,36:28,37:29,38:h,43:31,45:32,46:42,47:f,49:43,59:d,60:p,79:y,80:g,81:m,82:v,83:b,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,111:S,112:A,113:M,114:N,115:D,116:O,117:B,118:L,119:I,120:R},{8:61,10:[1,62],15:F},t([10,15],[2,6]),t(a,[2,17]),t(a,[2,18]),t(a,[2,19]),{20:[1,65],21:[1,66],22:P,27:64,30:67},t(j,[2,11]),t(j,[2,12]),t(j,[2,13]),t(j,[2,14]),t(j,[2,15]),t(j,[2,16]),{9:69,20:Y,21:z,23:U,44:70,71:74,74:[1,75],75:[1,76]},{9:77,20:Y,21:z,23:U},{9:78,20:Y,21:z,23:U},{9:79,20:Y,21:z,23:U},{9:80,20:Y,21:z,23:U},{9:81,20:Y,21:z,23:U},{9:83,20:Y,21:z,22:[1,82],23:U},t(j,[2,44]),t(q,[2,51],{30:84,22:P}),{22:[1,85]},{22:[1,86]},{22:[1,87]},{22:[1,88]},{26:H,47:$,59:W,60:V,77:[1,92],84:G,90:91,91:[1,89],93:[1,90],98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(j,[2,154]),t(j,[2,155]),t(j,[2,156]),t(j,[2,157]),t(ot,[2,52],{48:[1,111]}),t(st,[2,70],{109:123,40:[1,112],47:f,50:[1,113],52:[1,114],54:[1,115],56:[1,116],58:[1,117],59:d,60:p,62:[1,118],64:[1,119],66:[1,120],67:[1,121],69:[1,122],84:_,88:x,98:w,99:k,102:T,104:E,105:C,115:D,116:O,117:B,118:L,119:I,120:R}),t(ct,[2,146]),t(ct,[2,171]),t(ct,[2,172]),t(ct,[2,173]),t(ct,[2,174]),t(ct,[2,175]),t(ct,[2,176]),t(ct,[2,177]),t(ct,[2,178]),t(ct,[2,179]),t(ct,[2,180]),t(ct,[2,181]),t(ct,[2,182]),t(ct,[2,183]),t(ct,[2,184]),t(ct,[2,185]),t(ct,[2,186]),{9:124,20:Y,21:z,23:U},{11:125,14:[1,126]},t(ut,[2,8]),t(a,[2,20]),t(a,[2,26]),t(a,[2,27]),{21:[1,127]},t(lt,[2,34],{30:128,22:P}),t(j,[2,35]),{45:129,46:42,47:f,49:43,59:d,60:p,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,115:D,116:O,117:B,118:L,119:I,120:R},t(ht,[2,45]),t(ht,[2,46]),t(ht,[2,47]),t(ft,[2,74],{72:130,61:[1,132],73:[1,131]}),{22:dt,24:pt,26:yt,38:gt,39:133,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t([47,59,60,61,73,84,88,98,99,102,104,105,115,116,117,118,119,120],[2,76]),t(j,[2,36]),t(j,[2,37]),t(j,[2,38]),t(j,[2,39]),t(j,[2,40]),{22:dt,24:pt,26:yt,38:gt,39:157,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(Ot,o,{17:158}),t(q,[2,50],{47:Bt}),{26:H,47:$,59:W,60:V,84:G,90:160,95:[1,161],98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},{88:[1,162],96:163,98:[1,164]},{26:H,47:$,59:W,60:V,84:G,88:[1,165],90:166,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},{26:H,47:$,59:W,60:V,84:G,90:167,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ut,[2,97],{22:[1,168],92:[1,169]}),t(ut,[2,101],{22:[1,170]}),t(ut,[2,105],{108:95,110:172,22:[1,171],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,115:tt,116:et,117:nt,118:rt,119:it,120:at}),t(ut,[2,107],{22:[1,173]}),t(Lt,[2,148]),t(Lt,[2,150]),t(Lt,[2,151]),t(Lt,[2,152]),t(Lt,[2,153]),t(It,[2,158]),t(It,[2,159]),t(It,[2,160]),t(It,[2,161]),t(It,[2,162]),t(It,[2,163]),t(It,[2,164]),t(It,[2,165]),t(It,[2,166]),t(It,[2,167]),t(It,[2,168]),t(It,[2,169]),t(It,[2,170]),{47:f,49:174,59:d,60:p,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,115:D,116:O,117:B,118:L,119:I,120:R},{22:dt,24:pt,26:yt,38:gt,39:175,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:177,42:mt,47:$,50:[1,176],59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:178,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:179,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:180,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{59:[1,181]},{22:dt,24:pt,26:yt,38:gt,39:182,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:183,42:mt,47:$,59:W,60:V,64:[1,184],66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:185,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:186,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:187,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ct,[2,147]),t(Rt,[2,3]),{8:188,15:F},{15:[2,7]},t(a,[2,28]),t(lt,[2,33]),t(q,[2,48],{30:189,22:P}),t(ft,[2,71],{22:[1,190]}),{22:[1,191]},{22:dt,24:pt,26:yt,38:gt,39:192,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,66:vt,74:bt,75:[1,193],76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(It,[2,78]),t(It,[2,80]),t(It,[2,136]),t(It,[2,137]),t(It,[2,138]),t(It,[2,139]),t(It,[2,140]),t(It,[2,141]),t(It,[2,142]),t(It,[2,143]),t(It,[2,144]),t(It,[2,145]),t(It,[2,81]),t(It,[2,82]),t(It,[2,83]),t(It,[2,84]),t(It,[2,85]),t(It,[2,86]),t(It,[2,87]),t(It,[2,88]),t(It,[2,89]),t(It,[2,90]),t(It,[2,91]),{9:196,20:Y,21:z,22:dt,23:U,24:pt,26:yt,38:gt,40:[1,195],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{18:18,19:19,20:s,21:c,22:u,23:l,32:24,33:25,34:26,35:27,36:28,37:29,38:h,42:[1,197],43:31,45:32,46:42,47:f,49:43,59:d,60:p,79:y,80:g,81:m,82:v,83:b,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,111:S,112:A,113:M,114:N,115:D,116:O,117:B,118:L,119:I,120:R},{22:P,30:198},{22:[1,199],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,108:95,110:172,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:[1,200]},{22:[1,201]},{22:[1,202],99:[1,203]},t(Ft,[2,119]),{22:[1,204]},{22:[1,205],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,108:95,110:172,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:[1,206],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,108:95,110:172,115:tt,116:et,117:nt,118:rt,119:it,120:at},{77:[1,207]},t(ut,[2,99],{22:[1,208]}),{77:[1,209],94:[1,210]},{77:[1,211]},t(Lt,[2,149]),{77:[1,212],94:[1,213]},t(ot,[2,54],{109:123,47:f,59:d,60:p,84:_,88:x,98:w,99:k,102:T,104:E,105:C,115:D,116:O,117:B,118:L,119:I,120:R}),{22:dt,24:pt,26:yt,38:gt,41:[1,214],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:215,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,51:[1,216],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,53:[1,217],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,55:[1,218],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,57:[1,219],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{60:[1,220]},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,63:[1,221],66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,65:[1,222],66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:223,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,41:[1,224],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,66:vt,68:[1,225],70:[1,226],74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,66:vt,68:[1,228],70:[1,227],74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{9:229,20:Y,21:z,23:U},t(q,[2,49],{47:Bt}),t(ft,[2,73]),t(ft,[2,72]),{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,61:[1,230],66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ft,[2,75]),t(It,[2,79]),{22:dt,24:pt,26:yt,38:gt,39:231,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(Ot,o,{17:232}),t(j,[2,43]),{46:233,47:f,49:43,59:d,60:p,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,115:D,116:O,117:B,118:L,119:I,120:R},{22:Pt,59:jt,60:Yt,79:zt,89:234,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:248,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:249,95:Ut,97:[1,250],98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:251,95:Ut,97:[1,252],98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{98:[1,253]},{22:Pt,59:jt,60:Yt,79:zt,89:254,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:255,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{26:H,47:$,59:W,60:V,84:G,90:256,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ut,[2,98]),{77:[1,257]},t(ut,[2,102],{22:[1,258]}),t(ut,[2,103]),t(ut,[2,106]),t(ut,[2,108],{22:[1,259]}),t(ut,[2,109]),t(st,[2,55]),{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,51:[1,260],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(st,[2,62]),t(st,[2,57]),t(st,[2,58]),t(st,[2,59]),{59:[1,261]},t(st,[2,61]),t(st,[2,63]),{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,65:[1,262],66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(st,[2,65]),t(st,[2,66]),t(st,[2,68]),t(st,[2,67]),t(st,[2,69]),t(Rt,[2,4]),t([22,47,59,60,84,88,98,99,102,104,105,115,116,117,118,119,120],[2,77]),{22:dt,24:pt,26:yt,38:gt,41:[1,263],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{18:18,19:19,20:s,21:c,22:u,23:l,32:24,33:25,34:26,35:27,36:28,37:29,38:h,42:[1,264],43:31,45:32,46:42,47:f,49:43,59:d,60:p,79:y,80:g,81:m,82:v,83:b,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,111:S,112:A,113:M,114:N,115:D,116:O,117:B,118:L,119:I,120:R},t(ot,[2,53]),t(ut,[2,111],{99:Xt}),t(Zt,[2,121],{101:266,22:Pt,59:jt,60:Yt,79:zt,95:Ut,98:qt,102:Ht,103:$t,104:Wt,105:Vt,106:Gt}),t(Qt,[2,123]),t(Qt,[2,125]),t(Qt,[2,126]),t(Qt,[2,127]),t(Qt,[2,128]),t(Qt,[2,129]),t(Qt,[2,130]),t(Qt,[2,131]),t(Qt,[2,132]),t(Qt,[2,133]),t(Qt,[2,134]),t(Qt,[2,135]),t(ut,[2,112],{99:Xt}),t(ut,[2,113],{99:Xt}),{22:[1,267]},t(ut,[2,114],{99:Xt}),{22:[1,268]},t(Ft,[2,120]),t(ut,[2,94],{99:Xt}),t(ut,[2,95],{99:Xt}),t(ut,[2,96],{108:95,110:172,26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,115:tt,116:et,117:nt,118:rt,119:it,120:at}),t(ut,[2,100]),{94:[1,269]},{94:[1,270]},{51:[1,271]},{61:[1,272]},{65:[1,273]},{9:274,20:Y,21:z,23:U},t(j,[2,42]),{22:Pt,59:jt,60:Yt,79:zt,95:Ut,98:qt,100:275,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},t(Qt,[2,124]),{26:H,47:$,59:W,60:V,84:G,90:276,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},{26:H,47:$,59:W,60:V,84:G,90:277,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ut,[2,104]),t(ut,[2,110]),t(st,[2,56]),{22:dt,24:pt,26:yt,38:gt,39:278,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(st,[2,64]),t(Ot,o,{17:279}),t(Zt,[2,122],{101:266,22:Pt,59:jt,60:Yt,79:zt,95:Ut,98:qt,102:Ht,103:$t,104:Wt,105:Vt,106:Gt}),t(ut,[2,117],{108:95,110:172,22:[1,280],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,115:tt,116:et,117:nt,118:rt,119:it,120:at}),t(ut,[2,118],{108:95,110:172,22:[1,281],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,115:tt,116:et,117:nt,118:rt,119:it,120:at}),{22:dt,24:pt,26:yt,38:gt,41:[1,282],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{18:18,19:19,20:s,21:c,22:u,23:l,32:24,33:25,34:26,35:27,36:28,37:29,38:h,42:[1,283],43:31,45:32,46:42,47:f,49:43,59:d,60:p,79:y,80:g,81:m,82:v,83:b,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,111:S,112:A,113:M,114:N,115:D,116:O,117:B,118:L,119:I,120:R},{22:Pt,59:jt,60:Yt,79:zt,89:284,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:285,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},t(st,[2,60]),t(j,[2,41]),t(ut,[2,115],{99:Xt}),t(ut,[2,116],{99:Xt})],defaultActions:{2:[2,1],9:[2,5],10:[2,2],126:[2,7]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},Jt={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),12;case 1:return this.begin("type_directive"),13;case 2:return this.popState(),this.begin("arg_directive"),10;case 3:return this.popState(),this.popState(),15;case 4:return 14;case 5:case 6:break;case 7:this.begin("string");break;case 8:case 17:case 20:case 23:case 26:this.popState();break;case 9:return"STR";case 10:return 79;case 11:return 88;case 12:return 80;case 13:return 97;case 14:return 81;case 15:return 82;case 16:this.begin("href");break;case 18:return 93;case 19:this.begin("callbackname");break;case 21:this.popState(),this.begin("callbackargs");break;case 22:return 91;case 24:return 92;case 25:this.begin("click");break;case 27:return 83;case 28:case 29:return t.lex.firstGraph()&&this.begin("dir"),24;case 30:return 38;case 31:return 42;case 32:case 33:case 34:case 35:return 94;case 36:return this.popState(),25;case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 45:case 46:return this.popState(),26;case 47:return 111;case 48:return 112;case 49:return 113;case 50:return 114;case 51:return 98;case 52:return 104;case 53:return 48;case 54:return 60;case 55:return 47;case 56:return 20;case 57:return 99;case 58:return 119;case 59:case 60:case 61:return 75;case 62:case 63:case 64:return 74;case 65:return 52;case 66:return 53;case 67:return 54;case 68:return 55;case 69:return 56;case 70:return 57;case 71:return 58;case 72:return 62;case 73:return 63;case 74:return 102;case 75:return 105;case 76:return 120;case 77:return 117;case 78:return 106;case 79:case 80:return 118;case 81:return 107;case 82:return 66;case 83:return 85;case 84:return"SEP";case 85:return 84;case 86:return 59;case 87:return 68;case 88:return 67;case 89:return 70;case 90:return 69;case 91:return 115;case 92:return 116;case 93:return 61;case 94:return 50;case 95:return 51;case 96:return 40;case 97:return 41;case 98:return 64;case 99:return 65;case 100:return 126;case 101:return 21;case 102:return 22;case 103:return 23}},rules:[/^(?:%%\{)/,/^(?:((?:(?!\}%%)[^:.])*))/,/^(?::)/,/^(?:\}%%)/,/^(?:((?:(?!\}%%).|\n)*))/,/^(?:%%(?!\{)[^\n]*)/,/^(?:[^\}]%%[^\n]*)/,/^(?:["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:style\b)/,/^(?:default\b)/,/^(?:linkStyle\b)/,/^(?:interpolate\b)/,/^(?:classDef\b)/,/^(?:class\b)/,/^(?:href[\s]+["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:call[\s]+)/,/^(?:\([\s]*\))/,/^(?:\()/,/^(?:[^(]*)/,/^(?:\))/,/^(?:[^)]*)/,/^(?:click[\s]+)/,/^(?:[\s\n])/,/^(?:[^\s\n]*)/,/^(?:graph\b)/,/^(?:flowchart\b)/,/^(?:subgraph\b)/,/^(?:end\b\s*)/,/^(?:_self\b)/,/^(?:_blank\b)/,/^(?:_parent\b)/,/^(?:_top\b)/,/^(?:(\r?\n)*\s*\n)/,/^(?:\s*LR\b)/,/^(?:\s*RL\b)/,/^(?:\s*TB\b)/,/^(?:\s*BT\b)/,/^(?:\s*TD\b)/,/^(?:\s*BR\b)/,/^(?:\s*<)/,/^(?:\s*>)/,/^(?:\s*\^)/,/^(?:\s*v\b)/,/^(?:.*direction\s+TB[^\n]*)/,/^(?:.*direction\s+BT[^\n]*)/,/^(?:.*direction\s+RL[^\n]*)/,/^(?:.*direction\s+LR[^\n]*)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?::::)/,/^(?::)/,/^(?:&)/,/^(?:;)/,/^(?:,)/,/^(?:\*)/,/^(?:\s*[xo<]?--+[-xo>]\s*)/,/^(?:\s*[xo<]?==+[=xo>]\s*)/,/^(?:\s*[xo<]?-?\.+-[xo>]?\s*)/,/^(?:\s*[xo<]?--\s*)/,/^(?:\s*[xo<]?==\s*)/,/^(?:\s*[xo<]?-\.\s*)/,/^(?:\(-)/,/^(?:-\))/,/^(?:\(\[)/,/^(?:\]\))/,/^(?:\[\[)/,/^(?:\]\])/,/^(?:\[\|)/,/^(?:\[\()/,/^(?:\)\])/,/^(?:-)/,/^(?:\.)/,/^(?:[\_])/,/^(?:\+)/,/^(?:%)/,/^(?:=)/,/^(?:=)/,/^(?:<)/,/^(?:>)/,/^(?:\^)/,/^(?:\\\|)/,/^(?:v\b)/,/^(?:[A-Za-z]+)/,/^(?:\\\])/,/^(?:\[\/)/,/^(?:\/\])/,/^(?:\[\\)/,/^(?:[!"#$%&'*+,-.`?\\_/])/,/^(?:[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|[\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE]|[\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA]|[\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0]|[\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977]|[\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2]|[\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A]|[\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39]|[\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8]|[\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C]|[\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C]|[\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99]|[\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0]|[\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D]|[\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3]|[\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10]|[\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1]|[\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81]|[\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3]|[\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6]|[\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A]|[\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081]|[\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D]|[\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0]|[\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310]|[\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C]|[\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711]|[\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7]|[\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C]|[\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16]|[\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF]|[\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC]|[\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D]|[\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D]|[\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3]|[\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F]|[\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128]|[\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184]|[\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3]|[\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6]|[\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE]|[\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C]|[\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D]|[\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC]|[\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B]|[\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788]|[\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805]|[\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB]|[\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28]|[\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5]|[\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4]|[\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E]|[\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D]|[\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36]|[\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D]|[\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]|[\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF]|[\uFFD2-\uFFD7\uFFDA-\uFFDC])/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:")/,/^(?:(\r?\n)+)/,/^(?:\s)/,/^(?:$)/],conditions:{close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},callbackargs:{rules:[23,24],inclusive:!1},callbackname:{rules:[20,21,22],inclusive:!1},href:{rules:[17,18],inclusive:!1},click:{rules:[26,27],inclusive:!1},vertex:{rules:[],inclusive:!1},dir:{rules:[36,37,38,39,40,41,42,43,44,45,46],inclusive:!1},string:{rules:[8,9],inclusive:!1},INITIAL:{rules:[0,5,6,7,10,11,12,13,14,15,16,19,25,28,29,30,31,32,33,34,35,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103],inclusive:!0}}};function te(){this.yy={}}return Kt.lexer=Jt,te.prototype=Kt,Kt.Parser=te,new te}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(5354).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},9959:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,3],n=[1,5],r=[7,9,11,12,13,14,15,16,17,18,19,20,22,29,34],i=[1,15],a=[1,16],o=[1,17],s=[1,18],c=[1,19],u=[1,20],l=[1,21],h=[1,22],f=[1,23],d=[1,25],p=[1,27],y=[1,30],g=[5,7,9,11,12,13,14,15,16,17,18,19,20,22,29,34],m={trace:function(){},yy:{},symbols_:{error:2,start:3,directive:4,gantt:5,document:6,EOF:7,line:8,SPACE:9,statement:10,NL:11,dateFormat:12,inclusiveEndDates:13,topAxis:14,axisFormat:15,excludes:16,includes:17,todayMarker:18,title:19,section:20,clickStatement:21,taskTxt:22,taskData:23,openDirective:24,typeDirective:25,closeDirective:26,":":27,argDirective:28,click:29,callbackname:30,callbackargs:31,href:32,clickStatementDebug:33,open_directive:34,type_directive:35,arg_directive:36,close_directive:37,$accept:0,$end:1},terminals_:{2:"error",5:"gantt",7:"EOF",9:"SPACE",11:"NL",12:"dateFormat",13:"inclusiveEndDates",14:"topAxis",15:"axisFormat",16:"excludes",17:"includes",18:"todayMarker",19:"title",20:"section",22:"taskTxt",23:"taskData",27:":",29:"click",30:"callbackname",31:"callbackargs",32:"href",34:"open_directive",35:"type_directive",36:"arg_directive",37:"close_directive"},productions_:[0,[3,2],[3,3],[6,0],[6,2],[8,2],[8,1],[8,1],[8,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,2],[10,1],[4,4],[4,6],[21,2],[21,3],[21,3],[21,4],[21,3],[21,4],[21,2],[33,2],[33,3],[33,3],[33,4],[33,3],[33,4],[33,2],[24,1],[25,1],[28,1],[26,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 2:return a[s-1];case 3:case 7:case 8:this.$=[];break;case 4:a[s-1].push(a[s]),this.$=a[s-1];break;case 5:case 6:this.$=a[s];break;case 9:r.setDateFormat(a[s].substr(11)),this.$=a[s].substr(11);break;case 10:r.enableInclusiveEndDates(),this.$=a[s].substr(18);break;case 11:r.TopAxis(),this.$=a[s].substr(8);break;case 12:r.setAxisFormat(a[s].substr(11)),this.$=a[s].substr(11);break;case 13:r.setExcludes(a[s].substr(9)),this.$=a[s].substr(9);break;case 14:r.setIncludes(a[s].substr(9)),this.$=a[s].substr(9);break;case 15:r.setTodayMarker(a[s].substr(12)),this.$=a[s].substr(12);break;case 16:r.setTitle(a[s].substr(6)),this.$=a[s].substr(6);break;case 17:r.addSection(a[s].substr(8)),this.$=a[s].substr(8);break;case 19:r.addTask(a[s-1],a[s]),this.$="task";break;case 23:this.$=a[s-1],r.setClickEvent(a[s-1],a[s],null);break;case 24:this.$=a[s-2],r.setClickEvent(a[s-2],a[s-1],a[s]);break;case 25:this.$=a[s-2],r.setClickEvent(a[s-2],a[s-1],null),r.setLink(a[s-2],a[s]);break;case 26:this.$=a[s-3],r.setClickEvent(a[s-3],a[s-2],a[s-1]),r.setLink(a[s-3],a[s]);break;case 27:this.$=a[s-2],r.setClickEvent(a[s-2],a[s],null),r.setLink(a[s-2],a[s-1]);break;case 28:this.$=a[s-3],r.setClickEvent(a[s-3],a[s-1],a[s]),r.setLink(a[s-3],a[s-2]);break;case 29:this.$=a[s-1],r.setLink(a[s-1],a[s]);break;case 30:case 36:this.$=a[s-1]+" "+a[s];break;case 31:case 32:case 34:this.$=a[s-2]+" "+a[s-1]+" "+a[s];break;case 33:case 35:this.$=a[s-3]+" "+a[s-2]+" "+a[s-1]+" "+a[s];break;case 37:r.parseDirective("%%{","open_directive");break;case 38:r.parseDirective(a[s],"type_directive");break;case 39:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 40:r.parseDirective("}%%","close_directive","gantt")}},table:[{3:1,4:2,5:e,24:4,34:n},{1:[3]},{3:6,4:2,5:e,24:4,34:n},t(r,[2,3],{6:7}),{25:8,35:[1,9]},{35:[2,37]},{1:[2,1]},{4:26,7:[1,10],8:11,9:[1,12],10:13,11:[1,14],12:i,13:a,14:o,15:s,16:c,17:u,18:l,19:h,20:f,21:24,22:d,24:4,29:p,34:n},{26:28,27:[1,29],37:y},t([27,37],[2,38]),t(r,[2,8],{1:[2,2]}),t(r,[2,4]),{4:26,10:31,12:i,13:a,14:o,15:s,16:c,17:u,18:l,19:h,20:f,21:24,22:d,24:4,29:p,34:n},t(r,[2,6]),t(r,[2,7]),t(r,[2,9]),t(r,[2,10]),t(r,[2,11]),t(r,[2,12]),t(r,[2,13]),t(r,[2,14]),t(r,[2,15]),t(r,[2,16]),t(r,[2,17]),t(r,[2,18]),{23:[1,32]},t(r,[2,20]),{30:[1,33],32:[1,34]},{11:[1,35]},{28:36,36:[1,37]},{11:[2,40]},t(r,[2,5]),t(r,[2,19]),t(r,[2,23],{31:[1,38],32:[1,39]}),t(r,[2,29],{30:[1,40]}),t(g,[2,21]),{26:41,37:y},{37:[2,39]},t(r,[2,24],{32:[1,42]}),t(r,[2,25]),t(r,[2,27],{31:[1,43]}),{11:[1,44]},t(r,[2,26]),t(r,[2,28]),t(g,[2,22])],defaultActions:{5:[2,37],6:[2,1],30:[2,40],37:[2,39]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},v={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),34;case 1:return this.begin("type_directive"),35;case 2:return this.popState(),this.begin("arg_directive"),27;case 3:return this.popState(),this.popState(),37;case 4:return 36;case 5:case 6:case 7:case 9:case 10:case 11:break;case 8:return 11;case 12:this.begin("href");break;case 13:case 16:case 19:case 22:this.popState();break;case 14:return 32;case 15:this.begin("callbackname");break;case 17:this.popState(),this.begin("callbackargs");break;case 18:return 30;case 20:return 31;case 21:this.begin("click");break;case 23:return 29;case 24:return 5;case 25:return 12;case 26:return 13;case 27:return 14;case 28:return 15;case 29:return 17;case 30:return 16;case 31:return 18;case 32:return"date";case 33:return 19;case 34:return 20;case 35:return 22;case 36:return 23;case 37:return 27;case 38:return 7;case 39:return"INVALID"}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%%(?!\{)*[^\n]*)/i,/^(?:[^\}]%%*[^\n]*)/i,/^(?:%%*[^\n]*[\n]*)/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:href[\s]+["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:call[\s]+)/i,/^(?:\([\s]*\))/i,/^(?:\()/i,/^(?:[^(]*)/i,/^(?:\))/i,/^(?:[^)]*)/i,/^(?:click[\s]+)/i,/^(?:[\s\n])/i,/^(?:[^\s\n]*)/i,/^(?:gantt\b)/i,/^(?:dateFormat\s[^#\n;]+)/i,/^(?:inclusiveEndDates\b)/i,/^(?:topAxis\b)/i,/^(?:axisFormat\s[^#\n;]+)/i,/^(?:includes\s[^#\n;]+)/i,/^(?:excludes\s[^#\n;]+)/i,/^(?:todayMarker\s[^\n;]+)/i,/^(?:\d\d\d\d-\d\d-\d\d\b)/i,/^(?:title\s[^#\n;]+)/i,/^(?:section\s[^#:\n;]+)/i,/^(?:[^#:\n;]+)/i,/^(?::[^#\n;]+)/i,/^(?::)/i,/^(?:$)/i,/^(?:.)/i],conditions:{close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},callbackargs:{rules:[19,20],inclusive:!1},callbackname:{rules:[16,17,18],inclusive:!1},href:{rules:[13,14],inclusive:!1},click:{rules:[22,23],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,11,12,15,21,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39],inclusive:!0}}};function b(){this.yy={}}return m.lexer=v,b.prototype=m,m.Parser=b,new b}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(6878).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},2553:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[2,3],n=[1,7],r=[7,12,15,17,19,20,21],i=[7,11,12,15,17,19,20,21],a=[2,20],o=[1,32],s={trace:function(){},yy:{},symbols_:{error:2,start:3,GG:4,":":5,document:6,EOF:7,DIR:8,options:9,body:10,OPT:11,NL:12,line:13,statement:14,COMMIT:15,commit_arg:16,BRANCH:17,ID:18,CHECKOUT:19,MERGE:20,RESET:21,reset_arg:22,STR:23,HEAD:24,reset_parents:25,CARET:26,$accept:0,$end:1},terminals_:{2:"error",4:"GG",5:":",7:"EOF",8:"DIR",11:"OPT",12:"NL",15:"COMMIT",17:"BRANCH",18:"ID",19:"CHECKOUT",20:"MERGE",21:"RESET",23:"STR",24:"HEAD",26:"CARET"},productions_:[0,[3,4],[3,5],[6,0],[6,2],[9,2],[9,1],[10,0],[10,2],[13,2],[13,1],[14,2],[14,2],[14,2],[14,2],[14,2],[16,0],[16,1],[22,2],[22,2],[25,0],[25,2]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 1:return a[s-1];case 2:return r.setDirection(a[s-3]),a[s-1];case 4:r.setOptions(a[s-1]),this.$=a[s];break;case 5:a[s-1]+=a[s],this.$=a[s-1];break;case 7:this.$=[];break;case 8:a[s-1].push(a[s]),this.$=a[s-1];break;case 9:this.$=a[s-1];break;case 11:r.commit(a[s]);break;case 12:r.branch(a[s]);break;case 13:r.checkout(a[s]);break;case 14:r.merge(a[s]);break;case 15:r.reset(a[s]);break;case 16:this.$="";break;case 17:this.$=a[s];break;case 18:this.$=a[s-1]+":"+a[s];break;case 19:this.$=a[s-1]+":"+r.count,r.count=0;break;case 20:r.count=0;break;case 21:r.count+=1}},table:[{3:1,4:[1,2]},{1:[3]},{5:[1,3],8:[1,4]},{6:5,7:e,9:6,12:n},{5:[1,8]},{7:[1,9]},t(r,[2,7],{10:10,11:[1,11]}),t(i,[2,6]),{6:12,7:e,9:6,12:n},{1:[2,1]},{7:[2,4],12:[1,15],13:13,14:14,15:[1,16],17:[1,17],19:[1,18],20:[1,19],21:[1,20]},t(i,[2,5]),{7:[1,21]},t(r,[2,8]),{12:[1,22]},t(r,[2,10]),{12:[2,16],16:23,23:[1,24]},{18:[1,25]},{18:[1,26]},{18:[1,27]},{18:[1,30],22:28,24:[1,29]},{1:[2,2]},t(r,[2,9]),{12:[2,11]},{12:[2,17]},{12:[2,12]},{12:[2,13]},{12:[2,14]},{12:[2,15]},{12:a,25:31,26:o},{12:a,25:33,26:o},{12:[2,18]},{12:a,25:34,26:o},{12:[2,19]},{12:[2,21]}],defaultActions:{9:[2,1],21:[2,2],23:[2,11],24:[2,17],25:[2,12],26:[2,13],27:[2,14],28:[2,15],31:[2,18],33:[2,19],34:[2,21]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},c={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return 12;case 1:case 2:case 3:break;case 4:return 4;case 5:return 15;case 6:return 17;case 7:return 20;case 8:return 21;case 9:return 19;case 10:case 11:return 8;case 12:return 5;case 13:return 26;case 14:this.begin("options");break;case 15:case 18:this.popState();break;case 16:return 11;case 17:this.begin("string");break;case 19:return 23;case 20:return 18;case 21:return 7}},rules:[/^(?:(\r?\n)+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:gitGraph\b)/i,/^(?:commit\b)/i,/^(?:branch\b)/i,/^(?:merge\b)/i,/^(?:reset\b)/i,/^(?:checkout\b)/i,/^(?:LR\b)/i,/^(?:BT\b)/i,/^(?::)/i,/^(?:\^)/i,/^(?:options\r?\n)/i,/^(?:end\r?\n)/i,/^(?:[^\n]+\r?\n)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[a-zA-Z][-_\.a-zA-Z0-9]*[-_a-zA-Z0-9])/i,/^(?:$)/i],conditions:{options:{rules:[15,16],inclusive:!1},string:{rules:[18,19],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,20,21],inclusive:!0}}};function u(){this.yy={}}return s.lexer=c,u.prototype=s,s.Parser=u,new u}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(8183).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},6765:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[6,9,10],n={trace:function(){},yy:{},symbols_:{error:2,start:3,info:4,document:5,EOF:6,line:7,statement:8,NL:9,showInfo:10,$accept:0,$end:1},terminals_:{2:"error",4:"info",6:"EOF",9:"NL",10:"showInfo"},productions_:[0,[3,3],[5,0],[5,2],[7,1],[7,1],[8,1]],performAction:function(t,e,n,r,i,a,o){switch(a.length,i){case 1:return r;case 4:break;case 6:r.setInfo(!0)}},table:[{3:1,4:[1,2]},{1:[3]},t(e,[2,2],{5:3}),{6:[1,4],7:5,8:6,9:[1,7],10:[1,8]},{1:[2,1]},t(e,[2,3]),t(e,[2,4]),t(e,[2,5]),t(e,[2,6])],defaultActions:{4:[2,1]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},r={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return 4;case 1:return 9;case 2:return"space";case 3:return 10;case 4:return 6;case 5:return"TXT"}},rules:[/^(?:info\b)/i,/^(?:[\s\n\r]+)/i,/^(?:[\s]+)/i,/^(?:showInfo\b)/i,/^(?:$)/i,/^(?:.)/i],conditions:{INITIAL:{rules:[0,1,2,3,4,5],inclusive:!0}}};function i(){this.yy={}}return n.lexer=r,i.prototype=n,n.Parser=i,new i}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(1428).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},7062:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,4],n=[1,5],r=[1,6],i=[1,7],a=[1,9],o=[1,11,13,20,21,22,23],s=[2,5],c=[1,6,11,13,20,21,22,23],u=[20,21,22],l=[2,8],h=[1,18],f=[1,19],d=[1,24],p=[6,20,21,22,23],y={trace:function(){},yy:{},symbols_:{error:2,start:3,eol:4,directive:5,PIE:6,document:7,showData:8,line:9,statement:10,txt:11,value:12,title:13,title_value:14,openDirective:15,typeDirective:16,closeDirective:17,":":18,argDirective:19,NEWLINE:20,";":21,EOF:22,open_directive:23,type_directive:24,arg_directive:25,close_directive:26,$accept:0,$end:1},terminals_:{2:"error",6:"PIE",8:"showData",11:"txt",12:"value",13:"title",14:"title_value",18:":",20:"NEWLINE",21:";",22:"EOF",23:"open_directive",24:"type_directive",25:"arg_directive",26:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,3],[7,0],[7,2],[9,2],[10,0],[10,2],[10,2],[10,1],[5,3],[5,5],[4,1],[4,1],[4,1],[15,1],[16,1],[19,1],[17,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 4:r.setShowData(!0);break;case 7:this.$=a[s-1];break;case 9:r.addSection(a[s-1],r.cleanupValue(a[s]));break;case 10:this.$=a[s].trim(),r.setTitle(this.$);break;case 17:r.parseDirective("%%{","open_directive");break;case 18:r.parseDirective(a[s],"type_directive");break;case 19:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 20:r.parseDirective("}%%","close_directive","pie")}},table:[{3:1,4:2,5:3,6:e,15:8,20:n,21:r,22:i,23:a},{1:[3]},{3:10,4:2,5:3,6:e,15:8,20:n,21:r,22:i,23:a},{3:11,4:2,5:3,6:e,15:8,20:n,21:r,22:i,23:a},t(o,s,{7:12,8:[1,13]}),t(c,[2,14]),t(c,[2,15]),t(c,[2,16]),{16:14,24:[1,15]},{24:[2,17]},{1:[2,1]},{1:[2,2]},t(u,l,{15:8,9:16,10:17,5:20,1:[2,3],11:h,13:f,23:a}),t(o,s,{7:21}),{17:22,18:[1,23],26:d},t([18,26],[2,18]),t(o,[2,6]),{4:25,20:n,21:r,22:i},{12:[1,26]},{14:[1,27]},t(u,[2,11]),t(u,l,{15:8,9:16,10:17,5:20,1:[2,4],11:h,13:f,23:a}),t(p,[2,12]),{19:28,25:[1,29]},t(p,[2,20]),t(o,[2,7]),t(u,[2,9]),t(u,[2,10]),{17:30,26:d},{26:[2,19]},t(p,[2,13])],defaultActions:{9:[2,17],10:[2,1],11:[2,2],29:[2,19]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},g={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),23;case 1:return this.begin("type_directive"),24;case 2:return this.popState(),this.begin("arg_directive"),18;case 3:return this.popState(),this.popState(),26;case 4:return 25;case 5:case 6:case 8:case 9:break;case 7:return 20;case 10:return this.begin("title"),13;case 11:return this.popState(),"title_value";case 12:this.begin("string");break;case 13:this.popState();break;case 14:return"txt";case 15:return 6;case 16:return 8;case 17:return"value";case 18:return 22}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n\r]+)/i,/^(?:%%[^\n]*)/i,/^(?:[\s]+)/i,/^(?:title\b)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:pie\b)/i,/^(?:showData\b)/i,/^(?::[\s]*[\d]+(?:\.[\d]+)?)/i,/^(?:$)/i],conditions:{close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},title:{rules:[11],inclusive:!1},string:{rules:[13,14],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,12,15,16,17,18],inclusive:!0}}};function m(){this.yy={}}return y.lexer=g,m.prototype=y,y.Parser=m,new m}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(4551).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},3176:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,3],n=[1,5],r=[1,17],i=[2,10],a=[1,21],o=[1,22],s=[1,23],c=[1,24],u=[1,25],l=[1,26],h=[1,19],f=[1,27],d=[1,28],p=[1,31],y=[66,67],g=[5,8,14,35,36,37,38,39,40,48,55,57,66,67],m=[5,6,8,14,35,36,37,38,39,40,48,66,67],v=[1,51],b=[1,52],_=[1,53],x=[1,54],w=[1,55],k=[1,56],T=[1,57],E=[57,58],C=[1,69],S=[1,65],A=[1,66],M=[1,67],N=[1,68],D=[1,70],O=[1,74],B=[1,75],L=[1,72],I=[1,73],R=[5,8,14,35,36,37,38,39,40,48,66,67],F={trace:function(){},yy:{},symbols_:{error:2,start:3,directive:4,NEWLINE:5,RD:6,diagram:7,EOF:8,openDirective:9,typeDirective:10,closeDirective:11,":":12,argDirective:13,open_directive:14,type_directive:15,arg_directive:16,close_directive:17,requirementDef:18,elementDef:19,relationshipDef:20,requirementType:21,requirementName:22,STRUCT_START:23,requirementBody:24,ID:25,COLONSEP:26,id:27,TEXT:28,text:29,RISK:30,riskLevel:31,VERIFYMTHD:32,verifyType:33,STRUCT_STOP:34,REQUIREMENT:35,FUNCTIONAL_REQUIREMENT:36,INTERFACE_REQUIREMENT:37,PERFORMANCE_REQUIREMENT:38,PHYSICAL_REQUIREMENT:39,DESIGN_CONSTRAINT:40,LOW_RISK:41,MED_RISK:42,HIGH_RISK:43,VERIFY_ANALYSIS:44,VERIFY_DEMONSTRATION:45,VERIFY_INSPECTION:46,VERIFY_TEST:47,ELEMENT:48,elementName:49,elementBody:50,TYPE:51,type:52,DOCREF:53,ref:54,END_ARROW_L:55,relationship:56,LINE:57,END_ARROW_R:58,CONTAINS:59,COPIES:60,DERIVES:61,SATISFIES:62,VERIFIES:63,REFINES:64,TRACES:65,unqString:66,qString:67,$accept:0,$end:1},terminals_:{2:"error",5:"NEWLINE",6:"RD",8:"EOF",12:":",14:"open_directive",15:"type_directive",16:"arg_directive",17:"close_directive",23:"STRUCT_START",25:"ID",26:"COLONSEP",28:"TEXT",30:"RISK",32:"VERIFYMTHD",34:"STRUCT_STOP",35:"REQUIREMENT",36:"FUNCTIONAL_REQUIREMENT",37:"INTERFACE_REQUIREMENT",38:"PERFORMANCE_REQUIREMENT",39:"PHYSICAL_REQUIREMENT",40:"DESIGN_CONSTRAINT",41:"LOW_RISK",42:"MED_RISK",43:"HIGH_RISK",44:"VERIFY_ANALYSIS",45:"VERIFY_DEMONSTRATION",46:"VERIFY_INSPECTION",47:"VERIFY_TEST",48:"ELEMENT",51:"TYPE",53:"DOCREF",55:"END_ARROW_L",57:"LINE",58:"END_ARROW_R",59:"CONTAINS",60:"COPIES",61:"DERIVES",62:"SATISFIES",63:"VERIFIES",64:"REFINES",65:"TRACES",66:"unqString",67:"qString"},productions_:[0,[3,3],[3,2],[3,4],[4,3],[4,5],[9,1],[10,1],[13,1],[11,1],[7,0],[7,2],[7,2],[7,2],[7,2],[7,2],[18,5],[24,5],[24,5],[24,5],[24,5],[24,2],[24,1],[21,1],[21,1],[21,1],[21,1],[21,1],[21,1],[31,1],[31,1],[31,1],[33,1],[33,1],[33,1],[33,1],[19,5],[50,5],[50,5],[50,2],[50,1],[20,5],[20,5],[56,1],[56,1],[56,1],[56,1],[56,1],[56,1],[56,1],[22,1],[22,1],[27,1],[27,1],[29,1],[29,1],[49,1],[49,1],[52,1],[52,1],[54,1],[54,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 6:r.parseDirective("%%{","open_directive");break;case 7:r.parseDirective(a[s],"type_directive");break;case 8:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 9:r.parseDirective("}%%","close_directive","pie");break;case 10:this.$=[];break;case 16:r.addRequirement(a[s-3],a[s-4]);break;case 17:r.setNewReqId(a[s-2]);break;case 18:r.setNewReqText(a[s-2]);break;case 19:r.setNewReqRisk(a[s-2]);break;case 20:r.setNewReqVerifyMethod(a[s-2]);break;case 23:this.$=r.RequirementType.REQUIREMENT;break;case 24:this.$=r.RequirementType.FUNCTIONAL_REQUIREMENT;break;case 25:this.$=r.RequirementType.INTERFACE_REQUIREMENT;break;case 26:this.$=r.RequirementType.PERFORMANCE_REQUIREMENT;break;case 27:this.$=r.RequirementType.PHYSICAL_REQUIREMENT;break;case 28:this.$=r.RequirementType.DESIGN_CONSTRAINT;break;case 29:this.$=r.RiskLevel.LOW_RISK;break;case 30:this.$=r.RiskLevel.MED_RISK;break;case 31:this.$=r.RiskLevel.HIGH_RISK;break;case 32:this.$=r.VerifyType.VERIFY_ANALYSIS;break;case 33:this.$=r.VerifyType.VERIFY_DEMONSTRATION;break;case 34:this.$=r.VerifyType.VERIFY_INSPECTION;break;case 35:this.$=r.VerifyType.VERIFY_TEST;break;case 36:r.addElement(a[s-3]);break;case 37:r.setNewElementType(a[s-2]);break;case 38:r.setNewElementDocRef(a[s-2]);break;case 41:r.addRelationship(a[s-2],a[s],a[s-4]);break;case 42:r.addRelationship(a[s-2],a[s-4],a[s]);break;case 43:this.$=r.Relationships.CONTAINS;break;case 44:this.$=r.Relationships.COPIES;break;case 45:this.$=r.Relationships.DERIVES;break;case 46:this.$=r.Relationships.SATISFIES;break;case 47:this.$=r.Relationships.VERIFIES;break;case 48:this.$=r.Relationships.REFINES;break;case 49:this.$=r.Relationships.TRACES}},table:[{3:1,4:2,6:e,9:4,14:n},{1:[3]},{3:7,4:2,5:[1,6],6:e,9:4,14:n},{5:[1,8]},{10:9,15:[1,10]},{15:[2,6]},{3:11,4:2,6:e,9:4,14:n},{1:[2,2]},{4:16,5:r,7:12,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{11:29,12:[1,30],17:p},t([12,17],[2,7]),{1:[2,1]},{8:[1,32]},{4:16,5:r,7:33,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{4:16,5:r,7:34,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{4:16,5:r,7:35,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{4:16,5:r,7:36,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{4:16,5:r,7:37,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{22:38,66:[1,39],67:[1,40]},{49:41,66:[1,42],67:[1,43]},{55:[1,44],57:[1,45]},t(y,[2,23]),t(y,[2,24]),t(y,[2,25]),t(y,[2,26]),t(y,[2,27]),t(y,[2,28]),t(g,[2,52]),t(g,[2,53]),t(m,[2,4]),{13:46,16:[1,47]},t(m,[2,9]),{1:[2,3]},{8:[2,11]},{8:[2,12]},{8:[2,13]},{8:[2,14]},{8:[2,15]},{23:[1,48]},{23:[2,50]},{23:[2,51]},{23:[1,49]},{23:[2,56]},{23:[2,57]},{56:50,59:v,60:b,61:_,62:x,63:w,64:k,65:T},{56:58,59:v,60:b,61:_,62:x,63:w,64:k,65:T},{11:59,17:p},{17:[2,8]},{5:[1,60]},{5:[1,61]},{57:[1,62]},t(E,[2,43]),t(E,[2,44]),t(E,[2,45]),t(E,[2,46]),t(E,[2,47]),t(E,[2,48]),t(E,[2,49]),{58:[1,63]},t(m,[2,5]),{5:C,24:64,25:S,28:A,30:M,32:N,34:D},{5:O,34:B,50:71,51:L,53:I},{27:76,66:f,67:d},{27:77,66:f,67:d},t(R,[2,16]),{26:[1,78]},{26:[1,79]},{26:[1,80]},{26:[1,81]},{5:C,24:82,25:S,28:A,30:M,32:N,34:D},t(R,[2,22]),t(R,[2,36]),{26:[1,83]},{26:[1,84]},{5:O,34:B,50:85,51:L,53:I},t(R,[2,40]),t(R,[2,41]),t(R,[2,42]),{27:86,66:f,67:d},{29:87,66:[1,88],67:[1,89]},{31:90,41:[1,91],42:[1,92],43:[1,93]},{33:94,44:[1,95],45:[1,96],46:[1,97],47:[1,98]},t(R,[2,21]),{52:99,66:[1,100],67:[1,101]},{54:102,66:[1,103],67:[1,104]},t(R,[2,39]),{5:[1,105]},{5:[1,106]},{5:[2,54]},{5:[2,55]},{5:[1,107]},{5:[2,29]},{5:[2,30]},{5:[2,31]},{5:[1,108]},{5:[2,32]},{5:[2,33]},{5:[2,34]},{5:[2,35]},{5:[1,109]},{5:[2,58]},{5:[2,59]},{5:[1,110]},{5:[2,60]},{5:[2,61]},{5:C,24:111,25:S,28:A,30:M,32:N,34:D},{5:C,24:112,25:S,28:A,30:M,32:N,34:D},{5:C,24:113,25:S,28:A,30:M,32:N,34:D},{5:C,24:114,25:S,28:A,30:M,32:N,34:D},{5:O,34:B,50:115,51:L,53:I},{5:O,34:B,50:116,51:L,53:I},t(R,[2,17]),t(R,[2,18]),t(R,[2,19]),t(R,[2,20]),t(R,[2,37]),t(R,[2,38])],defaultActions:{5:[2,6],7:[2,2],11:[2,1],32:[2,3],33:[2,11],34:[2,12],35:[2,13],36:[2,14],37:[2,15],39:[2,50],40:[2,51],42:[2,56],43:[2,57],47:[2,8],88:[2,54],89:[2,55],91:[2,29],92:[2,30],93:[2,31],95:[2,32],96:[2,33],97:[2,34],98:[2,35],100:[2,58],101:[2,59],103:[2,60],104:[2,61]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},P={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),14;case 1:return this.begin("type_directive"),15;case 2:return this.popState(),this.begin("arg_directive"),12;case 3:return this.popState(),this.popState(),17;case 4:return 16;case 5:return 5;case 6:case 7:case 8:break;case 9:return 8;case 10:return 6;case 11:return 23;case 12:return 34;case 13:return 26;case 14:return 25;case 15:return 28;case 16:return 30;case 17:return 32;case 18:return 35;case 19:return 36;case 20:return 37;case 21:return 38;case 22:return 39;case 23:return 40;case 24:return 41;case 25:return 42;case 26:return 43;case 27:return 44;case 28:return 45;case 29:return 46;case 30:return 47;case 31:return 48;case 32:return 59;case 33:return 60;case 34:return 61;case 35:return 62;case 36:return 63;case 37:return 64;case 38:return 65;case 39:return 51;case 40:return 53;case 41:return 55;case 42:return 58;case 43:return 57;case 44:this.begin("string");break;case 45:this.popState();break;case 46:return"qString";case 47:return e.yytext=e.yytext.trim(),66}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:(\r?\n)+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:$)/i,/^(?:requirementDiagram\b)/i,/^(?:\{)/i,/^(?:\})/i,/^(?::)/i,/^(?:id\b)/i,/^(?:text\b)/i,/^(?:risk\b)/i,/^(?:verifyMethod\b)/i,/^(?:requirement\b)/i,/^(?:functionalRequirement\b)/i,/^(?:interfaceRequirement\b)/i,/^(?:performanceRequirement\b)/i,/^(?:physicalRequirement\b)/i,/^(?:designConstraint\b)/i,/^(?:low\b)/i,/^(?:medium\b)/i,/^(?:high\b)/i,/^(?:analysis\b)/i,/^(?:demonstration\b)/i,/^(?:inspection\b)/i,/^(?:test\b)/i,/^(?:element\b)/i,/^(?:contains\b)/i,/^(?:copies\b)/i,/^(?:derives\b)/i,/^(?:satisfies\b)/i,/^(?:verifies\b)/i,/^(?:refines\b)/i,/^(?:traces\b)/i,/^(?:type\b)/i,/^(?:docref\b)/i,/^(?:<-)/i,/^(?:->)/i,/^(?:-)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[\w][^\r\n\{\<\>\-\=]*)/i],conditions:{close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},unqString:{rules:[],inclusive:!1},token:{rules:[],inclusive:!1},string:{rules:[45,46],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,47],inclusive:!0}}};function j(){this.yy={}}return F.lexer=P,j.prototype=F,F.Parser=j,new j}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(8800).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},6876:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,2],n=[1,3],r=[1,5],i=[1,7],a=[2,5],o=[1,15],s=[1,17],c=[1,18],u=[1,19],l=[1,21],h=[1,22],f=[1,23],d=[1,29],p=[1,30],y=[1,31],g=[1,32],m=[1,33],v=[1,34],b=[1,37],_=[1,38],x=[1,39],w=[1,40],k=[1,41],T=[1,42],E=[1,45],C=[1,4,5,16,20,22,23,24,30,32,33,34,35,36,38,40,41,42,46,47,48,49,57,67],S=[1,58],A=[4,5,16,20,22,23,24,30,32,33,34,35,36,38,42,46,47,48,49,57,67],M=[4,5,16,20,22,23,24,30,32,33,34,35,36,38,41,42,46,47,48,49,57,67],N=[4,5,16,20,22,23,24,30,32,33,34,35,36,38,40,42,46,47,48,49,57,67],D=[55,56,57],O=[1,4,5,7,16,20,22,23,24,30,32,33,34,35,36,38,40,41,42,46,47,48,49,57,67],B={trace:function(){},yy:{},symbols_:{error:2,start:3,SPACE:4,NEWLINE:5,directive:6,SD:7,document:8,line:9,statement:10,openDirective:11,typeDirective:12,closeDirective:13,":":14,argDirective:15,participant:16,actor:17,AS:18,restOfLine:19,participant_actor:20,signal:21,autonumber:22,activate:23,deactivate:24,note_statement:25,links_statement:26,link_statement:27,properties_statement:28,details_statement:29,title:30,text2:31,loop:32,end:33,rect:34,opt:35,alt:36,else_sections:37,par:38,par_sections:39,and:40,else:41,note:42,placement:43,over:44,actor_pair:45,links:46,link:47,properties:48,details:49,spaceList:50,",":51,left_of:52,right_of:53,signaltype:54,"+":55,"-":56,ACTOR:57,SOLID_OPEN_ARROW:58,DOTTED_OPEN_ARROW:59,SOLID_ARROW:60,DOTTED_ARROW:61,SOLID_CROSS:62,DOTTED_CROSS:63,SOLID_POINT:64,DOTTED_POINT:65,TXT:66,open_directive:67,type_directive:68,arg_directive:69,close_directive:70,$accept:0,$end:1},terminals_:{2:"error",4:"SPACE",5:"NEWLINE",7:"SD",14:":",16:"participant",18:"AS",19:"restOfLine",20:"participant_actor",22:"autonumber",23:"activate",24:"deactivate",30:"title",32:"loop",33:"end",34:"rect",35:"opt",36:"alt",38:"par",40:"and",41:"else",42:"note",44:"over",46:"links",47:"link",48:"properties",49:"details",51:",",52:"left_of",53:"right_of",55:"+",56:"-",57:"ACTOR",58:"SOLID_OPEN_ARROW",59:"DOTTED_OPEN_ARROW",60:"SOLID_ARROW",61:"DOTTED_ARROW",62:"SOLID_CROSS",63:"DOTTED_CROSS",64:"SOLID_POINT",65:"DOTTED_POINT",66:"TXT",67:"open_directive",68:"type_directive",69:"arg_directive",70:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,2],[8,0],[8,2],[9,2],[9,1],[9,1],[6,4],[6,6],[10,5],[10,3],[10,5],[10,3],[10,2],[10,1],[10,3],[10,3],[10,2],[10,2],[10,2],[10,2],[10,2],[10,3],[10,4],[10,4],[10,4],[10,4],[10,4],[10,1],[39,1],[39,4],[37,1],[37,4],[25,4],[25,4],[26,3],[27,3],[28,3],[29,3],[50,2],[50,1],[45,3],[45,1],[43,1],[43,1],[21,5],[21,5],[21,4],[17,1],[54,1],[54,1],[54,1],[54,1],[54,1],[54,1],[54,1],[54,1],[31,1],[11,1],[12,1],[15,1],[13,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 4:return r.apply(a[s]),a[s];case 5:case 9:this.$=[];break;case 6:a[s-1].push(a[s]),this.$=a[s-1];break;case 7:case 8:case 45:this.$=a[s];break;case 12:a[s-3].type="addParticipant",a[s-3].description=r.parseMessage(a[s-1]),this.$=a[s-3];break;case 13:a[s-1].type="addParticipant",this.$=a[s-1];break;case 14:a[s-3].type="addActor",a[s-3].description=r.parseMessage(a[s-1]),this.$=a[s-3];break;case 15:a[s-1].type="addActor",this.$=a[s-1];break;case 17:r.enableSequenceNumbers();break;case 18:this.$={type:"activeStart",signalType:r.LINETYPE.ACTIVE_START,actor:a[s-1]};break;case 19:this.$={type:"activeEnd",signalType:r.LINETYPE.ACTIVE_END,actor:a[s-1]};break;case 25:this.$=[{type:"setTitle",text:a[s-1]}];break;case 26:a[s-1].unshift({type:"loopStart",loopText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.LOOP_START}),a[s-1].push({type:"loopEnd",loopText:a[s-2],signalType:r.LINETYPE.LOOP_END}),this.$=a[s-1];break;case 27:a[s-1].unshift({type:"rectStart",color:r.parseMessage(a[s-2]),signalType:r.LINETYPE.RECT_START}),a[s-1].push({type:"rectEnd",color:r.parseMessage(a[s-2]),signalType:r.LINETYPE.RECT_END}),this.$=a[s-1];break;case 28:a[s-1].unshift({type:"optStart",optText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.OPT_START}),a[s-1].push({type:"optEnd",optText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.OPT_END}),this.$=a[s-1];break;case 29:a[s-1].unshift({type:"altStart",altText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.ALT_START}),a[s-1].push({type:"altEnd",signalType:r.LINETYPE.ALT_END}),this.$=a[s-1];break;case 30:a[s-1].unshift({type:"parStart",parText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.PAR_START}),a[s-1].push({type:"parEnd",signalType:r.LINETYPE.PAR_END}),this.$=a[s-1];break;case 33:this.$=a[s-3].concat([{type:"and",parText:r.parseMessage(a[s-1]),signalType:r.LINETYPE.PAR_AND},a[s]]);break;case 35:this.$=a[s-3].concat([{type:"else",altText:r.parseMessage(a[s-1]),signalType:r.LINETYPE.ALT_ELSE},a[s]]);break;case 36:this.$=[a[s-1],{type:"addNote",placement:a[s-2],actor:a[s-1].actor,text:a[s]}];break;case 37:a[s-2]=[].concat(a[s-1],a[s-1]).slice(0,2),a[s-2][0]=a[s-2][0].actor,a[s-2][1]=a[s-2][1].actor,this.$=[a[s-1],{type:"addNote",placement:r.PLACEMENT.OVER,actor:a[s-2].slice(0,2),text:a[s]}];break;case 38:this.$=[a[s-1],{type:"addLinks",actor:a[s-1].actor,text:a[s]}];break;case 39:this.$=[a[s-1],{type:"addALink",actor:a[s-1].actor,text:a[s]}];break;case 40:this.$=[a[s-1],{type:"addProperties",actor:a[s-1].actor,text:a[s]}];break;case 41:this.$=[a[s-1],{type:"addDetails",actor:a[s-1].actor,text:a[s]}];break;case 44:this.$=[a[s-2],a[s]];break;case 46:this.$=r.PLACEMENT.LEFTOF;break;case 47:this.$=r.PLACEMENT.RIGHTOF;break;case 48:this.$=[a[s-4],a[s-1],{type:"addMessage",from:a[s-4].actor,to:a[s-1].actor,signalType:a[s-3],msg:a[s]},{type:"activeStart",signalType:r.LINETYPE.ACTIVE_START,actor:a[s-1]}];break;case 49:this.$=[a[s-4],a[s-1],{type:"addMessage",from:a[s-4].actor,to:a[s-1].actor,signalType:a[s-3],msg:a[s]},{type:"activeEnd",signalType:r.LINETYPE.ACTIVE_END,actor:a[s-4]}];break;case 50:this.$=[a[s-3],a[s-1],{type:"addMessage",from:a[s-3].actor,to:a[s-1].actor,signalType:a[s-2],msg:a[s]}];break;case 51:this.$={type:"addParticipant",actor:a[s]};break;case 52:this.$=r.LINETYPE.SOLID_OPEN;break;case 53:this.$=r.LINETYPE.DOTTED_OPEN;break;case 54:this.$=r.LINETYPE.SOLID;break;case 55:this.$=r.LINETYPE.DOTTED;break;case 56:this.$=r.LINETYPE.SOLID_CROSS;break;case 57:this.$=r.LINETYPE.DOTTED_CROSS;break;case 58:this.$=r.LINETYPE.SOLID_POINT;break;case 59:this.$=r.LINETYPE.DOTTED_POINT;break;case 60:this.$=r.parseMessage(a[s].trim().substring(1));break;case 61:r.parseDirective("%%{","open_directive");break;case 62:r.parseDirective(a[s],"type_directive");break;case 63:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 64:r.parseDirective("}%%","close_directive","sequence")}},table:[{3:1,4:e,5:n,6:4,7:r,11:6,67:i},{1:[3]},{3:8,4:e,5:n,6:4,7:r,11:6,67:i},{3:9,4:e,5:n,6:4,7:r,11:6,67:i},{3:10,4:e,5:n,6:4,7:r,11:6,67:i},t([1,4,5,16,20,22,23,24,30,32,34,35,36,38,42,46,47,48,49,57,67],a,{8:11}),{12:12,68:[1,13]},{68:[2,61]},{1:[2,1]},{1:[2,2]},{1:[2,3]},{1:[2,4],4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},{13:43,14:[1,44],70:E},t([14,70],[2,62]),t(C,[2,6]),{6:35,10:46,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},t(C,[2,8]),t(C,[2,9]),{17:47,57:T},{17:48,57:T},{5:[1,49]},t(C,[2,17]),{17:50,57:T},{17:51,57:T},{5:[1,52]},{5:[1,53]},{5:[1,54]},{5:[1,55]},{5:[1,56]},{31:57,66:S},{19:[1,59]},{19:[1,60]},{19:[1,61]},{19:[1,62]},{19:[1,63]},t(C,[2,31]),{54:64,58:[1,65],59:[1,66],60:[1,67],61:[1,68],62:[1,69],63:[1,70],64:[1,71],65:[1,72]},{43:73,44:[1,74],52:[1,75],53:[1,76]},{17:77,57:T},{17:78,57:T},{17:79,57:T},{17:80,57:T},t([5,18,51,58,59,60,61,62,63,64,65,66],[2,51]),{5:[1,81]},{15:82,69:[1,83]},{5:[2,64]},t(C,[2,7]),{5:[1,85],18:[1,84]},{5:[1,87],18:[1,86]},t(C,[2,16]),{5:[1,88]},{5:[1,89]},t(C,[2,20]),t(C,[2,21]),t(C,[2,22]),t(C,[2,23]),t(C,[2,24]),{5:[1,90]},{5:[2,60]},t(A,a,{8:91}),t(A,a,{8:92}),t(A,a,{8:93}),t(M,a,{37:94,8:95}),t(N,a,{39:96,8:97}),{17:100,55:[1,98],56:[1,99],57:T},t(D,[2,52]),t(D,[2,53]),t(D,[2,54]),t(D,[2,55]),t(D,[2,56]),t(D,[2,57]),t(D,[2,58]),t(D,[2,59]),{17:101,57:T},{17:103,45:102,57:T},{57:[2,46]},{57:[2,47]},{31:104,66:S},{31:105,66:S},{31:106,66:S},{31:107,66:S},t(O,[2,10]),{13:108,70:E},{70:[2,63]},{19:[1,109]},t(C,[2,13]),{19:[1,110]},t(C,[2,15]),t(C,[2,18]),t(C,[2,19]),t(C,[2,25]),{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[1,111],34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[1,112],34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[1,113],34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},{33:[1,114]},{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[2,34],34:y,35:g,36:m,38:v,41:[1,115],42:b,46:_,47:x,48:w,49:k,57:T,67:i},{33:[1,116]},{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[2,32],34:y,35:g,36:m,38:v,40:[1,117],42:b,46:_,47:x,48:w,49:k,57:T,67:i},{17:118,57:T},{17:119,57:T},{31:120,66:S},{31:121,66:S},{31:122,66:S},{51:[1,123],66:[2,45]},{5:[2,38]},{5:[2,39]},{5:[2,40]},{5:[2,41]},{5:[1,124]},{5:[1,125]},{5:[1,126]},t(C,[2,26]),t(C,[2,27]),t(C,[2,28]),t(C,[2,29]),{19:[1,127]},t(C,[2,30]),{19:[1,128]},{31:129,66:S},{31:130,66:S},{5:[2,50]},{5:[2,36]},{5:[2,37]},{17:131,57:T},t(O,[2,11]),t(C,[2,12]),t(C,[2,14]),t(M,a,{8:95,37:132}),t(N,a,{8:97,39:133}),{5:[2,48]},{5:[2,49]},{66:[2,44]},{33:[2,35]},{33:[2,33]}],defaultActions:{7:[2,61],8:[2,1],9:[2,2],10:[2,3],45:[2,64],58:[2,60],75:[2,46],76:[2,47],83:[2,63],104:[2,38],105:[2,39],106:[2,40],107:[2,41],120:[2,50],121:[2,36],122:[2,37],129:[2,48],130:[2,49],131:[2,44],132:[2,35],133:[2,33]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},L={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),67;case 1:return this.begin("type_directive"),68;case 2:return this.popState(),this.begin("arg_directive"),14;case 3:return this.popState(),this.popState(),70;case 4:return 69;case 5:case 39:case 52:return 5;case 6:case 7:case 8:case 9:case 10:break;case 11:return this.begin("ID"),16;case 12:return this.begin("ID"),20;case 13:return e.yytext=e.yytext.trim(),this.begin("ALIAS"),57;case 14:return this.popState(),this.popState(),this.begin("LINE"),18;case 15:return this.popState(),this.popState(),5;case 16:return this.begin("LINE"),32;case 17:return this.begin("LINE"),34;case 18:return this.begin("LINE"),35;case 19:return this.begin("LINE"),36;case 20:return this.begin("LINE"),41;case 21:return this.begin("LINE"),38;case 22:return this.begin("LINE"),40;case 23:return this.popState(),19;case 24:return 33;case 25:return 52;case 26:return 53;case 27:return 46;case 28:return 47;case 29:return 48;case 30:return 49;case 31:return 44;case 32:return 42;case 33:return this.begin("ID"),23;case 34:return this.begin("ID"),24;case 35:return 30;case 36:return 7;case 37:return 22;case 38:return 51;case 40:return e.yytext=e.yytext.trim(),57;case 41:return 60;case 42:return 61;case 43:return 58;case 44:return 59;case 45:return 62;case 46:return 63;case 47:return 64;case 48:return 65;case 49:return 66;case 50:return 55;case 51:return 56;case 53:return"INVALID"}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:((?!\n)\s)+)/i,/^(?:#[^\n]*)/i,/^(?:%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:participant\b)/i,/^(?:actor\b)/i,/^(?:[^\->:\n,;]+?(?=((?!\n)\s)+as(?!\n)\s|[#\n;]|$))/i,/^(?:as\b)/i,/^(?:(?:))/i,/^(?:loop\b)/i,/^(?:rect\b)/i,/^(?:opt\b)/i,/^(?:alt\b)/i,/^(?:else\b)/i,/^(?:par\b)/i,/^(?:and\b)/i,/^(?:(?:[:]?(?:no)?wrap)?[^#\n;]*)/i,/^(?:end\b)/i,/^(?:left of\b)/i,/^(?:right of\b)/i,/^(?:links\b)/i,/^(?:link\b)/i,/^(?:properties\b)/i,/^(?:details\b)/i,/^(?:over\b)/i,/^(?:note\b)/i,/^(?:activate\b)/i,/^(?:deactivate\b)/i,/^(?:title\b)/i,/^(?:sequenceDiagram\b)/i,/^(?:autonumber\b)/i,/^(?:,)/i,/^(?:;)/i,/^(?:[^\+\->:\n,;]+((?!(-x|--x|-\)|--\)))[\-]*[^\+\->:\n,;]+)*)/i,/^(?:->>)/i,/^(?:-->>)/i,/^(?:->)/i,/^(?:-->)/i,/^(?:-[x])/i,/^(?:--[x])/i,/^(?:-[\)])/i,/^(?:--[\)])/i,/^(?::(?:(?:no)?wrap)?[^#\n;]+)/i,/^(?:\+)/i,/^(?:-)/i,/^(?:$)/i,/^(?:.)/i],conditions:{open_directive:{rules:[1,8],inclusive:!1},type_directive:{rules:[2,3,8],inclusive:!1},arg_directive:{rules:[3,4,8],inclusive:!1},ID:{rules:[7,8,13],inclusive:!1},ALIAS:{rules:[7,8,14,15],inclusive:!1},LINE:{rules:[7,8,23],inclusive:!1},INITIAL:{rules:[0,5,6,8,9,10,11,12,16,17,18,19,20,21,22,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53],inclusive:!0}}};function I(){this.yy={}}return B.lexer=L,I.prototype=B,B.Parser=I,new I}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(1993).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},3584:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,2],n=[1,3],r=[1,5],i=[1,7],a=[2,5],o=[1,15],s=[1,17],c=[1,19],u=[1,20],l=[1,21],h=[1,22],f=[1,30],d=[1,23],p=[1,24],y=[1,25],g=[1,26],m=[1,27],v=[1,32],b=[1,33],_=[1,34],x=[1,35],w=[1,31],k=[1,38],T=[1,4,5,14,15,17,19,20,22,23,24,25,26,27,36,37,38,39,42,45],E=[1,4,5,12,13,14,15,17,19,20,22,23,24,25,26,27,36,37,38,39,42,45],C=[1,4,5,7,14,15,17,19,20,22,23,24,25,26,27,36,37,38,39,42,45],S=[4,5,14,15,17,19,20,22,23,24,25,26,27,36,37,38,39,42,45],A={trace:function(){},yy:{},symbols_:{error:2,start:3,SPACE:4,NL:5,directive:6,SD:7,document:8,line:9,statement:10,idStatement:11,DESCR:12,"--\x3e":13,HIDE_EMPTY:14,scale:15,WIDTH:16,COMPOSIT_STATE:17,STRUCT_START:18,STRUCT_STOP:19,STATE_DESCR:20,AS:21,ID:22,FORK:23,JOIN:24,CHOICE:25,CONCURRENT:26,note:27,notePosition:28,NOTE_TEXT:29,direction:30,openDirective:31,typeDirective:32,closeDirective:33,":":34,argDirective:35,direction_tb:36,direction_bt:37,direction_rl:38,direction_lr:39,eol:40,";":41,EDGE_STATE:42,left_of:43,right_of:44,open_directive:45,type_directive:46,arg_directive:47,close_directive:48,$accept:0,$end:1},terminals_:{2:"error",4:"SPACE",5:"NL",7:"SD",12:"DESCR",13:"--\x3e",14:"HIDE_EMPTY",15:"scale",16:"WIDTH",17:"COMPOSIT_STATE",18:"STRUCT_START",19:"STRUCT_STOP",20:"STATE_DESCR",21:"AS",22:"ID",23:"FORK",24:"JOIN",25:"CHOICE",26:"CONCURRENT",27:"note",29:"NOTE_TEXT",34:":",36:"direction_tb",37:"direction_bt",38:"direction_rl",39:"direction_lr",41:";",42:"EDGE_STATE",43:"left_of",44:"right_of",45:"open_directive",46:"type_directive",47:"arg_directive",48:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,2],[8,0],[8,2],[9,2],[9,1],[9,1],[10,1],[10,2],[10,3],[10,4],[10,1],[10,2],[10,1],[10,4],[10,3],[10,6],[10,1],[10,1],[10,1],[10,1],[10,4],[10,4],[10,1],[10,1],[6,3],[6,5],[30,1],[30,1],[30,1],[30,1],[40,1],[40,1],[11,1],[11,1],[28,1],[28,1],[31,1],[32,1],[35,1],[33,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 4:return r.setRootDoc(a[s]),a[s];case 5:this.$=[];break;case 6:"nl"!=a[s]&&(a[s-1].push(a[s]),this.$=a[s-1]);break;case 7:case 8:case 36:case 37:this.$=a[s];break;case 9:this.$="nl";break;case 10:this.$={stmt:"state",id:a[s],type:"default",description:""};break;case 11:this.$={stmt:"state",id:a[s-1],type:"default",description:r.trimColon(a[s])};break;case 12:this.$={stmt:"relation",state1:{stmt:"state",id:a[s-2],type:"default",description:""},state2:{stmt:"state",id:a[s],type:"default",description:""}};break;case 13:this.$={stmt:"relation",state1:{stmt:"state",id:a[s-3],type:"default",description:""},state2:{stmt:"state",id:a[s-1],type:"default",description:""},description:a[s].substr(1).trim()};break;case 17:this.$={stmt:"state",id:a[s-3],type:"default",description:"",doc:a[s-1]};break;case 18:var c=a[s],u=a[s-2].trim();if(a[s].match(":")){var l=a[s].split(":");c=l[0],u=[u,l[1]]}this.$={stmt:"state",id:c,type:"default",description:u};break;case 19:this.$={stmt:"state",id:a[s-3],type:"default",description:a[s-5],doc:a[s-1]};break;case 20:this.$={stmt:"state",id:a[s],type:"fork"};break;case 21:this.$={stmt:"state",id:a[s],type:"join"};break;case 22:this.$={stmt:"state",id:a[s],type:"choice"};break;case 23:this.$={stmt:"state",id:r.getDividerId(),type:"divider"};break;case 24:this.$={stmt:"state",id:a[s-1].trim(),note:{position:a[s-2].trim(),text:a[s].trim()}};break;case 30:r.setDirection("TB"),this.$={stmt:"dir",value:"TB"};break;case 31:r.setDirection("BT"),this.$={stmt:"dir",value:"BT"};break;case 32:r.setDirection("RL"),this.$={stmt:"dir",value:"RL"};break;case 33:r.setDirection("LR"),this.$={stmt:"dir",value:"LR"};break;case 40:r.parseDirective("%%{","open_directive");break;case 41:r.parseDirective(a[s],"type_directive");break;case 42:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 43:r.parseDirective("}%%","close_directive","state")}},table:[{3:1,4:e,5:n,6:4,7:r,31:6,45:i},{1:[3]},{3:8,4:e,5:n,6:4,7:r,31:6,45:i},{3:9,4:e,5:n,6:4,7:r,31:6,45:i},{3:10,4:e,5:n,6:4,7:r,31:6,45:i},t([1,4,5,14,15,17,20,22,23,24,25,26,27,36,37,38,39,42,45],a,{8:11}),{32:12,46:[1,13]},{46:[2,40]},{1:[2,1]},{1:[2,2]},{1:[2,3]},{1:[2,4],4:o,5:s,6:28,9:14,10:16,11:18,14:c,15:u,17:l,20:h,22:f,23:d,24:p,25:y,26:g,27:m,30:29,31:6,36:v,37:b,38:_,39:x,42:w,45:i},{33:36,34:[1,37],48:k},t([34,48],[2,41]),t(T,[2,6]),{6:28,10:39,11:18,14:c,15:u,17:l,20:h,22:f,23:d,24:p,25:y,26:g,27:m,30:29,31:6,36:v,37:b,38:_,39:x,42:w,45:i},t(T,[2,8]),t(T,[2,9]),t(T,[2,10],{12:[1,40],13:[1,41]}),t(T,[2,14]),{16:[1,42]},t(T,[2,16],{18:[1,43]}),{21:[1,44]},t(T,[2,20]),t(T,[2,21]),t(T,[2,22]),t(T,[2,23]),{28:45,29:[1,46],43:[1,47],44:[1,48]},t(T,[2,26]),t(T,[2,27]),t(E,[2,36]),t(E,[2,37]),t(T,[2,30]),t(T,[2,31]),t(T,[2,32]),t(T,[2,33]),t(C,[2,28]),{35:49,47:[1,50]},t(C,[2,43]),t(T,[2,7]),t(T,[2,11]),{11:51,22:f,42:w},t(T,[2,15]),t(S,a,{8:52}),{22:[1,53]},{22:[1,54]},{21:[1,55]},{22:[2,38]},{22:[2,39]},{33:56,48:k},{48:[2,42]},t(T,[2,12],{12:[1,57]}),{4:o,5:s,6:28,9:14,10:16,11:18,14:c,15:u,17:l,19:[1,58],20:h,22:f,23:d,24:p,25:y,26:g,27:m,30:29,31:6,36:v,37:b,38:_,39:x,42:w,45:i},t(T,[2,18],{18:[1,59]}),{29:[1,60]},{22:[1,61]},t(C,[2,29]),t(T,[2,13]),t(T,[2,17]),t(S,a,{8:62}),t(T,[2,24]),t(T,[2,25]),{4:o,5:s,6:28,9:14,10:16,11:18,14:c,15:u,17:l,19:[1,63],20:h,22:f,23:d,24:p,25:y,26:g,27:m,30:29,31:6,36:v,37:b,38:_,39:x,42:w,45:i},t(T,[2,19])],defaultActions:{7:[2,40],8:[2,1],9:[2,2],10:[2,3],47:[2,38],48:[2,39],50:[2,42]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},M={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:case 26:return 36;case 1:case 27:return 37;case 2:case 28:return 38;case 3:case 29:return 39;case 4:return this.begin("open_directive"),45;case 5:return this.begin("type_directive"),46;case 6:return this.popState(),this.begin("arg_directive"),34;case 7:return this.popState(),this.popState(),48;case 8:return 47;case 9:case 10:case 12:case 13:case 14:case 15:case 39:case 45:break;case 11:case 59:return 5;case 16:return this.pushState("SCALE"),15;case 17:return 16;case 18:case 33:case 36:this.popState();break;case 19:this.pushState("STATE");break;case 20:case 23:return this.popState(),e.yytext=e.yytext.slice(0,-8).trim(),23;case 21:case 24:return this.popState(),e.yytext=e.yytext.slice(0,-8).trim(),24;case 22:case 25:return this.popState(),e.yytext=e.yytext.slice(0,-10).trim(),25;case 30:this.begin("STATE_STRING");break;case 31:return this.popState(),this.pushState("STATE_ID"),"AS";case 32:case 47:return this.popState(),"ID";case 34:return"STATE_DESCR";case 35:return 17;case 37:return this.popState(),this.pushState("struct"),18;case 38:return this.popState(),19;case 40:return this.begin("NOTE"),27;case 41:return this.popState(),this.pushState("NOTE_ID"),43;case 42:return this.popState(),this.pushState("NOTE_ID"),44;case 43:this.popState(),this.pushState("FLOATING_NOTE");break;case 44:return this.popState(),this.pushState("FLOATING_NOTE_ID"),"AS";case 46:return"NOTE_TEXT";case 48:return this.popState(),this.pushState("NOTE_TEXT"),22;case 49:return this.popState(),e.yytext=e.yytext.substr(2).trim(),29;case 50:return this.popState(),e.yytext=e.yytext.slice(0,-8).trim(),29;case 51:case 52:return 7;case 53:return 14;case 54:return 42;case 55:return 22;case 56:return e.yytext=e.yytext.trim(),12;case 57:return 13;case 58:return 26;case 60:return"INVALID"}},rules:[/^(?:.*direction\s+TB[^\n]*)/i,/^(?:.*direction\s+BT[^\n]*)/i,/^(?:.*direction\s+RL[^\n]*)/i,/^(?:.*direction\s+LR[^\n]*)/i,/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n]+)/i,/^(?:[\s]+)/i,/^(?:((?!\n)\s)+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:scale\s+)/i,/^(?:\d+)/i,/^(?:\s+width\b)/i,/^(?:state\s+)/i,/^(?:.*<>)/i,/^(?:.*<>)/i,/^(?:.*<>)/i,/^(?:.*\[\[fork\]\])/i,/^(?:.*\[\[join\]\])/i,/^(?:.*\[\[choice\]\])/i,/^(?:.*direction\s+TB[^\n]*)/i,/^(?:.*direction\s+BT[^\n]*)/i,/^(?:.*direction\s+RL[^\n]*)/i,/^(?:.*direction\s+LR[^\n]*)/i,/^(?:["])/i,/^(?:\s*as\s+)/i,/^(?:[^\n\{]*)/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[^\n\s\{]+)/i,/^(?:\n)/i,/^(?:\{)/i,/^(?:\})/i,/^(?:[\n])/i,/^(?:note\s+)/i,/^(?:left of\b)/i,/^(?:right of\b)/i,/^(?:")/i,/^(?:\s*as\s*)/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[^\n]*)/i,/^(?:\s*[^:\n\s\-]+)/i,/^(?:\s*:[^:\n;]+)/i,/^(?:[\s\S]*?end note\b)/i,/^(?:stateDiagram\s+)/i,/^(?:stateDiagram-v2\s+)/i,/^(?:hide empty description\b)/i,/^(?:\[\*\])/i,/^(?:[^:\n\s\-\{]+)/i,/^(?:\s*:[^:\n;]+)/i,/^(?:-->)/i,/^(?:--)/i,/^(?:$)/i,/^(?:.)/i],conditions:{LINE:{rules:[13,14],inclusive:!1},close_directive:{rules:[13,14],inclusive:!1},arg_directive:{rules:[7,8,13,14],inclusive:!1},type_directive:{rules:[6,7,13,14],inclusive:!1},open_directive:{rules:[5,13,14],inclusive:!1},struct:{rules:[13,14,19,26,27,28,29,38,39,40,54,55,56,57,58],inclusive:!1},FLOATING_NOTE_ID:{rules:[47],inclusive:!1},FLOATING_NOTE:{rules:[44,45,46],inclusive:!1},NOTE_TEXT:{rules:[49,50],inclusive:!1},NOTE_ID:{rules:[48],inclusive:!1},NOTE:{rules:[41,42,43],inclusive:!1},SCALE:{rules:[17,18],inclusive:!1},ALIAS:{rules:[],inclusive:!1},STATE_ID:{rules:[32],inclusive:!1},STATE_STRING:{rules:[33,34],inclusive:!1},FORK_STATE:{rules:[],inclusive:!1},STATE:{rules:[13,14,20,21,22,23,24,25,30,31,35,36,37],inclusive:!1},ID:{rules:[13,14],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,9,10,11,12,14,15,16,19,37,40,51,52,53,54,55,56,57,59,60],inclusive:!0}}};function N(){this.yy={}}return A.lexer=M,N.prototype=A,A.Parser=N,new N}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(3069).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},9763:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,2],n=[1,5],r=[6,9,11,17,18,19,21],i=[1,15],a=[1,16],o=[1,17],s=[1,21],c=[4,6,9,11,17,18,19,21],u={trace:function(){},yy:{},symbols_:{error:2,start:3,journey:4,document:5,EOF:6,directive:7,line:8,SPACE:9,statement:10,NEWLINE:11,openDirective:12,typeDirective:13,closeDirective:14,":":15,argDirective:16,title:17,section:18,taskName:19,taskData:20,open_directive:21,type_directive:22,arg_directive:23,close_directive:24,$accept:0,$end:1},terminals_:{2:"error",4:"journey",6:"EOF",9:"SPACE",11:"NEWLINE",15:":",17:"title",18:"section",19:"taskName",20:"taskData",21:"open_directive",22:"type_directive",23:"arg_directive",24:"close_directive"},productions_:[0,[3,3],[3,2],[5,0],[5,2],[8,2],[8,1],[8,1],[8,1],[7,4],[7,6],[10,1],[10,1],[10,2],[10,1],[12,1],[13,1],[16,1],[14,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 1:return a[s-1];case 3:case 7:case 8:this.$=[];break;case 4:a[s-1].push(a[s]),this.$=a[s-1];break;case 5:case 6:this.$=a[s];break;case 11:r.setTitle(a[s].substr(6)),this.$=a[s].substr(6);break;case 12:r.addSection(a[s].substr(8)),this.$=a[s].substr(8);break;case 13:r.addTask(a[s-1],a[s]),this.$="task";break;case 15:r.parseDirective("%%{","open_directive");break;case 16:r.parseDirective(a[s],"type_directive");break;case 17:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 18:r.parseDirective("}%%","close_directive","journey")}},table:[{3:1,4:e,7:3,12:4,21:n},{1:[3]},t(r,[2,3],{5:6}),{3:7,4:e,7:3,12:4,21:n},{13:8,22:[1,9]},{22:[2,15]},{6:[1,10],7:18,8:11,9:[1,12],10:13,11:[1,14],12:4,17:i,18:a,19:o,21:n},{1:[2,2]},{14:19,15:[1,20],24:s},t([15,24],[2,16]),t(r,[2,8],{1:[2,1]}),t(r,[2,4]),{7:18,10:22,12:4,17:i,18:a,19:o,21:n},t(r,[2,6]),t(r,[2,7]),t(r,[2,11]),t(r,[2,12]),{20:[1,23]},t(r,[2,14]),{11:[1,24]},{16:25,23:[1,26]},{11:[2,18]},t(r,[2,5]),t(r,[2,13]),t(c,[2,9]),{14:27,24:s},{24:[2,17]},{11:[1,28]},t(c,[2,10])],defaultActions:{5:[2,15],7:[2,2],21:[2,18],26:[2,17]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},l={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),21;case 1:return this.begin("type_directive"),22;case 2:return this.popState(),this.begin("arg_directive"),15;case 3:return this.popState(),this.popState(),24;case 4:return 23;case 5:case 6:case 8:case 9:break;case 7:return 11;case 10:return 4;case 11:return 17;case 12:return 18;case 13:return 19;case 14:return 20;case 15:return 15;case 16:return 6;case 17:return"INVALID"}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:journey\b)/i,/^(?:title\s[^#\n;]+)/i,/^(?:section\s[^#:\n;]+)/i,/^(?:[^#:\n;]+)/i,/^(?::[^#\n;]+)/i,/^(?::)/i,/^(?:$)/i,/^(?:.)/i],conditions:{open_directive:{rules:[1],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,11,12,13,14,15,16,17],inclusive:!0}}};function h(){this.yy={}}return u.lexer=l,h.prototype=u,u.Parser=h,new h}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(9143).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},9609:t=>{"use strict";var e=/^(%20|\s)*(javascript|data)/im,n=/[^\x20-\x7E]/gim,r=/^([^:]+):/gm,i=[".","/"];t.exports={sanitizeUrl:function(t){if(!t)return"about:blank";var a,o,s=t.replace(n,"").trim();return function(t){return i.indexOf(t[0])>-1}(s)?s:(o=s.match(r))?(a=o[0],e.test(a)?"about:blank":s):"about:blank"}}},3841:t=>{t.exports=function(t,e){return t.intersect(e)}},7458:(t,e,n)=>{"use strict";n.d(e,{default:()=>hC});var r=n(1941),i=n.n(r),a={debug:1,info:2,warn:3,error:4,fatal:5},o={debug:function(){},info:function(){},warn:function(){},error:function(){},fatal:function(){}},s=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"fatal";isNaN(t)&&(t=t.toLowerCase(),void 0!==a[t]&&(t=a[t])),o.trace=function(){},o.debug=function(){},o.info=function(){},o.warn=function(){},o.error=function(){},o.fatal=function(){},t<=a.fatal&&(o.fatal=console.error?console.error.bind(console,c("FATAL"),"color: orange"):console.log.bind(console,"",c("FATAL"))),t<=a.error&&(o.error=console.error?console.error.bind(console,c("ERROR"),"color: orange"):console.log.bind(console,"",c("ERROR"))),t<=a.warn&&(o.warn=console.warn?console.warn.bind(console,c("WARN"),"color: orange"):console.log.bind(console,"",c("WARN"))),t<=a.info&&(o.info=console.info?console.info.bind(console,c("INFO"),"color: lightblue"):console.log.bind(console,"",c("INFO"))),t<=a.debug&&(o.debug=console.debug?console.debug.bind(console,c("DEBUG"),"color: lightgreen"):console.log.bind(console,"",c("DEBUG")))},c=function(t){var e=i()().format("ss.SSS");return"%c".concat(e," : ").concat(t," : ")};function u(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n=i)&&(n=i)}return n}function l(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n>e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n>i||void 0===n&&i>=i)&&(n=i)}return n}function h(t){return t}var f=1e-6;function d(t){return"translate("+t+",0)"}function p(t){return"translate(0,"+t+")"}function y(t){return e=>+t(e)}function g(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function m(){return!this.__axis}function v(t,e){var n=[],r=null,i=null,a=6,o=6,s=3,c="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,u=1===t||4===t?-1:1,l=4===t||2===t?"x":"y",v=1===t||3===t?d:p;function b(d){var p=null==r?e.ticks?e.ticks.apply(e,n):e.domain():r,b=null==i?e.tickFormat?e.tickFormat.apply(e,n):h:i,_=Math.max(a,0)+s,x=e.range(),w=+x[0]+c,k=+x[x.length-1]+c,T=(e.bandwidth?g:y)(e.copy(),c),E=d.selection?d.selection():d,C=E.selectAll(".domain").data([null]),S=E.selectAll(".tick").data(p,e).order(),A=S.exit(),M=S.enter().append("g").attr("class","tick"),N=S.select("line"),D=S.select("text");C=C.merge(C.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),S=S.merge(M),N=N.merge(M.append("line").attr("stroke","currentColor").attr(l+"2",u*a)),D=D.merge(M.append("text").attr("fill","currentColor").attr(l,u*_).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),d!==E&&(C=C.transition(d),S=S.transition(d),N=N.transition(d),D=D.transition(d),A=A.transition(d).attr("opacity",f).attr("transform",(function(t){return isFinite(t=T(t))?v(t+c):this.getAttribute("transform")})),M.attr("opacity",f).attr("transform",(function(t){var e=this.parentNode.__axis;return v((e&&isFinite(e=e(t))?e:T(t))+c)}))),A.remove(),C.attr("d",4===t||2===t?o?"M"+u*o+","+w+"H"+c+"V"+k+"H"+u*o:"M"+c+","+w+"V"+k:o?"M"+w+","+u*o+"V"+c+"H"+k+"V"+u*o:"M"+w+","+c+"H"+k),S.attr("opacity",1).attr("transform",(function(t){return v(T(t)+c)})),N.attr(l+"2",u*a),D.attr(l,u*_).text(b),E.filter(m).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),E.each((function(){this.__axis=T}))}return b.scale=function(t){return arguments.length?(e=t,b):e},b.ticks=function(){return n=Array.from(arguments),b},b.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),b):n.slice()},b.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),b):r&&r.slice()},b.tickFormat=function(t){return arguments.length?(i=t,b):i},b.tickSize=function(t){return arguments.length?(a=o=+t,b):a},b.tickSizeInner=function(t){return arguments.length?(a=+t,b):a},b.tickSizeOuter=function(t){return arguments.length?(o=+t,b):o},b.tickPadding=function(t){return arguments.length?(s=+t,b):s},b.offset=function(t){return arguments.length?(c=+t,b):c},b}function b(){}function _(t){return null==t?b:function(){return this.querySelector(t)}}function x(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function w(){return[]}function k(t){return null==t?w:function(){return this.querySelectorAll(t)}}function T(t){return function(){return this.matches(t)}}function E(t){return function(e){return e.matches(t)}}var C=Array.prototype.find;function S(){return this.firstElementChild}var A=Array.prototype.filter;function M(){return Array.from(this.children)}function N(t){return new Array(t.length)}function D(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function O(t){return function(){return t}}function B(t,e,n,r,i,a){for(var o,s=0,c=e.length,u=a.length;se?1:t>=e?0:NaN}D.prototype={constructor:D,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var P="http://www.w3.org/1999/xhtml";const j={svg:"http://www.w3.org/2000/svg",xhtml:P,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Y(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),j.hasOwnProperty(e)?{space:j[e],local:t}:t}function z(t){return function(){this.removeAttribute(t)}}function U(t){return function(){this.removeAttributeNS(t.space,t.local)}}function q(t,e){return function(){this.setAttribute(t,e)}}function H(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function $(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function W(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function V(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function G(t){return function(){this.style.removeProperty(t)}}function X(t,e,n){return function(){this.style.setProperty(t,e,n)}}function Z(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function Q(t,e){return t.style.getPropertyValue(e)||V(t).getComputedStyle(t,null).getPropertyValue(e)}function K(t){return function(){delete this[t]}}function J(t,e){return function(){this[t]=e}}function tt(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function et(t){return t.trim().split(/^|\s+/)}function nt(t){return t.classList||new rt(t)}function rt(t){this._node=t,this._names=et(t.getAttribute("class")||"")}function it(t,e){for(var n=nt(t),r=-1,i=e.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}function Et(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var Nt=[null];function Dt(t,e){this._groups=t,this._parents=e}function Ot(){return new Dt([[document.documentElement]],Nt)}Dt.prototype=Ot.prototype={constructor:Dt,select:function(t){"function"!=typeof t&&(t=_(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i=x&&(x=_+1);!(b=g[x])&&++x=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=F);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a1?this.each((null==e?G:"function"==typeof e?Z:X)(t,e,null==n?"":n)):Q(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?K:"function"==typeof e?tt:J)(t,e)):this.node()[t]},classed:function(t,e){var n=et(t+"");if(arguments.length<2){for(var r=nt(this.node()),i=-1,a=n.length;++i{}};function It(){for(var t,e=0,n=arguments.length,r={};e=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function Pt(t,e){for(var n,r=0,i=t.length;r0)for(var n,r,i=new Array(n),a=0;a=0&&e._call.call(void 0,t),e=e._next;--qt}()}finally{qt=0,function(){for(var t,e,n=zt,r=1/0;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:zt=e);Ut=t,re(r)}(),Vt=0}}function ne(){var t=Xt.now(),e=t-Wt;e>1e3&&(Gt-=e,Wt=t)}function re(t){qt||(Ht&&(Ht=clearTimeout(Ht)),t-Vt>24?(t<1/0&&(Ht=setTimeout(ee,t-Xt.now()-Gt)),$t&&($t=clearInterval($t))):($t||(Wt=Xt.now(),$t=setInterval(ne,1e3)),qt=1,Zt(ee)))}function ie(t,e,n){var r=new Jt;return e=null==e?0:+e,r.restart((n=>{r.stop(),t(n+e)}),e,n),r}Jt.prototype=te.prototype={constructor:Jt,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?Qt():+n)+(null==e?0:+e),this._next||Ut===this||(Ut?Ut._next=this:zt=this,Ut=this),this._call=t,this._time=n,re()},stop:function(){this._call&&(this._call=null,this._time=1/0,re())}};var ae=Yt("start","end","cancel","interrupt"),oe=[];function se(t,e,n,r,i,a){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function a(c){var u,l,h,f;if(1!==n.state)return s();for(u in i)if((f=i[u]).name===n.name){if(3===f.state)return ie(a);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u0)throw new Error("too late; already scheduled");return n}function ue(t,e){var n=le(t,e);if(n.state>3)throw new Error("too late; already running");return n}function le(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function he(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var fe,de=180/Math.PI,pe={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function ye(t,e,n,r,i,a){var o,s,c;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(c=t*n+e*r)&&(n-=t*c,r-=e*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),t*r180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(i(n)+"rotate(",null,r)-2,x:he(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(a.rotate,o.rotate,s,c),function(t,e,n,a){t!==e?a.push({i:n.push(i(n)+"skewX(",null,r)-2,x:he(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(a.skewX,o.skewX,s,c),function(t,e,n,r,a,o){if(t!==n||e!==r){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:he(t,n)},{i:s-2,x:he(e,r)})}else 1===n&&1===r||a.push(i(a)+"scale("+n+","+r+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,c),a=o=null,function(t){for(var e,n=-1,r=c.length;++n>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Ue(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Ue(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=De.exec(t))?new $e(e[1],e[2],e[3],1):(e=Oe.exec(t))?new $e(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Be.exec(t))?Ue(e[1],e[2],e[3],e[4]):(e=Le.exec(t))?Ue(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Ie.exec(t))?Xe(e[1],e[2]/100,e[3]/100,1):(e=Re.exec(t))?Xe(e[1],e[2]/100,e[3]/100,e[4]):Fe.hasOwnProperty(t)?ze(Fe[t]):"transparent"===t?new $e(NaN,NaN,NaN,0):null}function ze(t){return new $e(t>>16&255,t>>8&255,255&t,1)}function Ue(t,e,n,r){return r<=0&&(t=e=n=NaN),new $e(t,e,n,r)}function qe(t){return t instanceof Te||(t=Ye(t)),t?new $e((t=t.rgb()).r,t.g,t.b,t.opacity):new $e}function He(t,e,n,r){return 1===arguments.length?qe(t):new $e(t,e,n,null==r?1:r)}function $e(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function We(){return"#"+Ge(this.r)+Ge(this.g)+Ge(this.b)}function Ve(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function Ge(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function Xe(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Qe(t,e,n,r)}function Ze(t){if(t instanceof Qe)return new Qe(t.h,t.s,t.l,t.opacity);if(t instanceof Te||(t=Ye(t)),!t)return new Qe;if(t instanceof Qe)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n0&&c<1?0:o,new Qe(o,s,c,t.opacity)}function Qe(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function Ke(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function Je(t,e,n,r,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*n+(1+3*t+3*a-3*o)*r+o*i)/6}we(Te,Ye,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:Pe,formatHex:Pe,formatHsl:function(){return Ze(this).formatHsl()},formatRgb:je,toString:je}),we($e,He,ke(Te,{brighter:function(t){return t=null==t?Ce:Math.pow(Ce,t),new $e(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?Ee:Math.pow(Ee,t),new $e(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:We,formatHex:We,formatRgb:Ve,toString:Ve})),we(Qe,(function(t,e,n,r){return 1===arguments.length?Ze(t):new Qe(t,e,n,null==r?1:r)}),ke(Te,{brighter:function(t){return t=null==t?Ce:Math.pow(Ce,t),new Qe(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?Ee:Math.pow(Ee,t),new Qe(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new $e(Ke(t>=240?t-240:t+120,i,r),Ke(t,i,r),Ke(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));const tn=t=>()=>t;function en(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):tn(isNaN(t)?e:t)}const nn=function t(e){var n=function(t){return 1==(t=+t)?en:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):tn(isNaN(e)?n:e)}}(e);function r(t,e){var r=n((t=He(t)).r,(e=He(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=en(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1);function rn(t){return function(e){var n,r,i=e.length,a=new Array(i),o=new Array(i),s=new Array(i);for(n=0;n=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=ra&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,c.push({i:o,x:he(n,r)})),a=on.lastIndex;return a=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?ce:ue;return function(){var o=a(this,t),s=o.on;s!==r&&(i=(r=s).copy()).on(e,n),o.on=i}}var En=Bt.prototype.constructor;function Cn(t){return function(){this.style.removeProperty(t)}}function Sn(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}function An(t,e,n){var r,i;function a(){var a=e.apply(this,arguments);return a!==i&&(r=(i=a)&&Sn(t,a,n)),r}return a._value=e,a}function Mn(t){return function(e){this.textContent=t.call(this,e)}}function Nn(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&Mn(r)),e}return r._value=t,r}var Dn=0;function On(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function Bn(){return++Dn}var Ln=Bt.prototype;On.prototype=function(t){return Bt().transition(t)}.prototype={constructor:On,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=_(t));for(var r=this._groups,i=r.length,a=new Array(i),o=0;o2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete a[i]):o=!1;o&&delete t.__transition}}(this,t)}))},Bt.prototype.transition=function(t){var e,n;t instanceof On?(e=t._id,t=t._name):(e=Bn(),(n=In).time=Qt(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,a=0;a>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?sr(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?sr(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Zn.exec(t))?new lr(e[1],e[2],e[3],1):(e=Qn.exec(t))?new lr(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Kn.exec(t))?sr(e[1],e[2],e[3],e[4]):(e=Jn.exec(t))?sr(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=tr.exec(t))?pr(e[1],e[2]/100,e[3]/100,1):(e=er.exec(t))?pr(e[1],e[2]/100,e[3]/100,e[4]):nr.hasOwnProperty(t)?or(nr[t]):"transparent"===t?new lr(NaN,NaN,NaN,0):null}function or(t){return new lr(t>>16&255,t>>8&255,255&t,1)}function sr(t,e,n,r){return r<=0&&(t=e=n=NaN),new lr(t,e,n,r)}function cr(t){return t instanceof qn||(t=ar(t)),t?new lr((t=t.rgb()).r,t.g,t.b,t.opacity):new lr}function ur(t,e,n,r){return 1===arguments.length?cr(t):new lr(t,e,n,null==r?1:r)}function lr(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function hr(){return"#"+dr(this.r)+dr(this.g)+dr(this.b)}function fr(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function dr(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function pr(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new gr(t,e,n,r)}function yr(t){if(t instanceof gr)return new gr(t.h,t.s,t.l,t.opacity);if(t instanceof qn||(t=ar(t)),!t)return new gr;if(t instanceof gr)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n0&&c<1?0:o,new gr(o,s,c,t.opacity)}function gr(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function mr(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}zn(qn,ar,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:rr,formatHex:rr,formatHsl:function(){return yr(this).formatHsl()},formatRgb:ir,toString:ir}),zn(lr,ur,Un(qn,{brighter:function(t){return t=null==t?$n:Math.pow($n,t),new lr(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?Hn:Math.pow(Hn,t),new lr(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:hr,formatHex:hr,formatRgb:fr,toString:fr})),zn(gr,(function(t,e,n,r){return 1===arguments.length?yr(t):new gr(t,e,n,null==r?1:r)}),Un(qn,{brighter:function(t){return t=null==t?$n:Math.pow($n,t),new gr(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?Hn:Math.pow(Hn,t),new gr(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new lr(mr(t>=240?t-240:t+120,i,r),mr(t,i,r),mr(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));const vr=Math.PI/180,br=180/Math.PI,_r=.96422,xr=.82521,wr=4/29,kr=6/29,Tr=3*kr*kr;function Er(t){if(t instanceof Cr)return new Cr(t.l,t.a,t.b,t.opacity);if(t instanceof Br)return Lr(t);t instanceof lr||(t=cr(t));var e,n,r=Nr(t.r),i=Nr(t.g),a=Nr(t.b),o=Sr((.2225045*r+.7168786*i+.0606169*a)/1);return r===i&&i===a?e=n=o:(e=Sr((.4360747*r+.3850649*i+.1430804*a)/_r),n=Sr((.0139322*r+.0971045*i+.7141733*a)/xr)),new Cr(116*o-16,500*(e-o),200*(o-n),t.opacity)}function Cr(t,e,n,r){this.l=+t,this.a=+e,this.b=+n,this.opacity=+r}function Sr(t){return t>.008856451679035631?Math.pow(t,1/3):t/Tr+wr}function Ar(t){return t>kr?t*t*t:Tr*(t-wr)}function Mr(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function Nr(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function Dr(t){if(t instanceof Br)return new Br(t.h,t.c,t.l,t.opacity);if(t instanceof Cr||(t=Er(t)),0===t.a&&0===t.b)return new Br(NaN,0()=>t;function Rr(t,e){return function(n){return t+n*e}}function Fr(t,e){var n=e-t;return n?Rr(t,n):Ir(isNaN(t)?e:t)}function Pr(t){return function(e,n){var r=t((e=Or(e)).h,(n=Or(n)).h),i=Fr(e.c,n.c),a=Fr(e.l,n.l),o=Fr(e.opacity,n.opacity);return function(t){return e.h=r(t),e.c=i(t),e.l=a(t),e.opacity=o(t),e+""}}}const jr=Pr((function(t,e){var n=e-t;return n?Rr(t,n>180||n<-180?n-360*Math.round(n/360):n):Ir(isNaN(t)?e:t)}));Pr(Fr);var Yr=Math.sqrt(50),zr=Math.sqrt(10),Ur=Math.sqrt(2);function qr(t,e,n){var r=(e-t)/Math.max(0,n),i=Math.floor(Math.log(r)/Math.LN10),a=r/Math.pow(10,i);return i>=0?(a>=Yr?10:a>=zr?5:a>=Ur?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(a>=Yr?10:a>=zr?5:a>=Ur?2:1)}function Hr(t,e,n){var r=Math.abs(e-t)/Math.max(0,n),i=Math.pow(10,Math.floor(Math.log(r)/Math.LN10)),a=r/i;return a>=Yr?i*=10:a>=zr?i*=5:a>=Ur&&(i*=2),ee?1:t>=e?0:NaN}function Wr(t){let e=t,n=t,r=t;function i(t,e,i=0,a=t.length){if(i>>1;r(t[n],e)<0?i=n+1:a=n}while(it(e)-n,n=$r,r=(e,n)=>$r(t(e),n)),{left:i,center:function(t,n,r=0,a=t.length){const o=i(t,n,r,a-1);return o>r&&e(t[o-1],n)>-e(t[o],n)?o-1:o},right:function(t,e,i=0,a=t.length){if(i>>1;r(t[n],e)<=0?i=n+1:a=n}while(i>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?gi(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?gi(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=ai.exec(t))?new bi(e[1],e[2],e[3],1):(e=oi.exec(t))?new bi(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=si.exec(t))?gi(e[1],e[2],e[3],e[4]):(e=ci.exec(t))?gi(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=ui.exec(t))?ki(e[1],e[2]/100,e[3]/100,1):(e=li.exec(t))?ki(e[1],e[2]/100,e[3]/100,e[4]):hi.hasOwnProperty(t)?yi(hi[t]):"transparent"===t?new bi(NaN,NaN,NaN,0):null}function yi(t){return new bi(t>>16&255,t>>8&255,255&t,1)}function gi(t,e,n,r){return r<=0&&(t=e=n=NaN),new bi(t,e,n,r)}function mi(t){return t instanceof Kr||(t=pi(t)),t?new bi((t=t.rgb()).r,t.g,t.b,t.opacity):new bi}function vi(t,e,n,r){return 1===arguments.length?mi(t):new bi(t,e,n,null==r?1:r)}function bi(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function _i(){return"#"+wi(this.r)+wi(this.g)+wi(this.b)}function xi(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function wi(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function ki(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Ei(t,e,n,r)}function Ti(t){if(t instanceof Ei)return new Ei(t.h,t.s,t.l,t.opacity);if(t instanceof Kr||(t=pi(t)),!t)return new Ei;if(t instanceof Ei)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n0&&c<1?0:o,new Ei(o,s,c,t.opacity)}function Ei(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function Ci(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function Si(t,e,n,r,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*n+(1+3*t+3*a-3*o)*r+o*i)/6}Zr(Kr,pi,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:fi,formatHex:fi,formatHsl:function(){return Ti(this).formatHsl()},formatRgb:di,toString:di}),Zr(bi,vi,Qr(Kr,{brighter:function(t){return t=null==t?ti:Math.pow(ti,t),new bi(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?Jr:Math.pow(Jr,t),new bi(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:_i,formatHex:_i,formatRgb:xi,toString:xi})),Zr(Ei,(function(t,e,n,r){return 1===arguments.length?Ti(t):new Ei(t,e,n,null==r?1:r)}),Qr(Kr,{brighter:function(t){return t=null==t?ti:Math.pow(ti,t),new Ei(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?Jr:Math.pow(Jr,t),new Ei(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new bi(Ci(t>=240?t-240:t+120,i,r),Ci(t,i,r),Ci(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));const Ai=t=>()=>t;function Mi(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Ai(isNaN(t)?e:t)}const Ni=function t(e){var n=function(t){return 1==(t=+t)?Mi:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):Ai(isNaN(e)?n:e)}}(e);function r(t,e){var r=n((t=vi(t)).r,(e=vi(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=Mi(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1);function Di(t){return function(e){var n,r,i=e.length,a=new Array(i),o=new Array(i),s=new Array(i);for(n=0;n=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=ra&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,c.push({i:o,x:Li(n,r)})),a=Fi.lastIndex;return ae&&(n=t,t=e,e=n),u=function(n){return Math.max(t,Math.min(e,n))}),r=c>2?Vi:Wi,i=a=null,h}function h(e){return null==e||isNaN(e=+e)?n:(i||(i=r(o.map(t),s,c)))(t(u(e)))}return h.invert=function(n){return u(e((a||(a=r(s,o.map(t),Li)))(n)))},h.domain=function(t){return arguments.length?(o=Array.from(t,Ui),l()):o.slice()},h.range=function(t){return arguments.length?(s=Array.from(t),l()):s.slice()},h.rangeRound=function(t){return s=Array.from(t),c=zi,l()},h.clamp=function(t){return arguments.length?(u=!!t||Hi,l()):u!==Hi},h.interpolate=function(t){return arguments.length?(c=t,l()):c},h.unknown=function(t){return arguments.length?(n=t,h):n},function(n,r){return t=n,e=r,l()}}()(Hi,Hi)}function Zi(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}var Qi,Ki=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Ji(t){if(!(e=Ki.exec(t)))throw new Error("invalid format: "+t);var e;return new ta({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function ta(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function ea(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}function na(t){return(t=ea(Math.abs(t)))?t[1]:NaN}function ra(t,e){var n=ea(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}Ji.prototype=ta.prototype,ta.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};const ia={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>ra(100*t,e),r:ra,s:function(t,e){var n=ea(t,e);if(!n)return t+"";var r=n[0],i=n[1],a=i-(Qi=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,o=r.length;return a===o?r:a>o?r+new Array(a-o+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+ea(t,Math.max(0,e+a-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function aa(t){return t}var oa,sa,ca,ua=Array.prototype.map,la=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function ha(t){var e=t.domain;return t.ticks=function(t){var n=e();return function(t,e,n){var r,i,a,o,s=-1;if(n=+n,(t=+t)==(e=+e)&&n>0)return[t];if((r=e0){let n=Math.round(t/o),r=Math.round(e/o);for(n*oe&&--r,a=new Array(i=r-n+1);++se&&--r,a=new Array(i=r-n+1);++s0;){if((i=qr(c,u,n))===r)return a[o]=c,a[s]=u,e(a);if(i>0)c=Math.floor(c/i)*i,u=Math.ceil(u/i)*i;else{if(!(i<0))break;c=Math.ceil(c*i)/i,u=Math.floor(u*i)/i}r=i}return t},t}function fa(){var t=Xi();return t.copy=function(){return Gi(t,fa())},Zi.apply(t,arguments),ha(t)}oa=function(t){var e,n,r=void 0===t.grouping||void 0===t.thousands?aa:(e=ua.call(t.grouping,Number),n=t.thousands+"",function(t,r){for(var i=t.length,a=[],o=0,s=e[0],c=0;i>0&&s>0&&(c+s+1>r&&(s=Math.max(1,r-c)),a.push(t.substring(i-=s,i+s)),!((c+=s+1)>r));)s=e[o=(o+1)%e.length];return a.reverse().join(n)}),i=void 0===t.currency?"":t.currency[0]+"",a=void 0===t.currency?"":t.currency[1]+"",o=void 0===t.decimal?".":t.decimal+"",s=void 0===t.numerals?aa:function(t){return function(e){return e.replace(/[0-9]/g,(function(e){return t[+e]}))}}(ua.call(t.numerals,String)),c=void 0===t.percent?"%":t.percent+"",u=void 0===t.minus?"−":t.minus+"",l=void 0===t.nan?"NaN":t.nan+"";function h(t){var e=(t=Ji(t)).fill,n=t.align,h=t.sign,f=t.symbol,d=t.zero,p=t.width,y=t.comma,g=t.precision,m=t.trim,v=t.type;"n"===v?(y=!0,v="g"):ia[v]||(void 0===g&&(g=12),m=!0,v="g"),(d||"0"===e&&"="===n)&&(d=!0,e="0",n="=");var b="$"===f?i:"#"===f&&/[boxX]/.test(v)?"0"+v.toLowerCase():"",_="$"===f?a:/[%p]/.test(v)?c:"",x=ia[v],w=/[defgprs%]/.test(v);function k(t){var i,a,c,f=b,k=_;if("c"===v)k=x(t)+k,t="";else{var T=(t=+t)<0||1/t<0;if(t=isNaN(t)?l:x(Math.abs(t),g),m&&(t=function(t){t:for(var e,n=t.length,r=1,i=-1;r0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t}(t)),T&&0==+t&&"+"!==h&&(T=!1),f=(T?"("===h?h:u:"-"===h||"("===h?"":h)+f,k=("s"===v?la[8+Qi/3]:"")+k+(T&&"("===h?")":""),w)for(i=-1,a=t.length;++i(c=t.charCodeAt(i))||c>57){k=(46===c?o+t.slice(i+1):t.slice(i))+k,t=t.slice(0,i);break}}y&&!d&&(t=r(t,1/0));var E=f.length+t.length+k.length,C=E>1)+f+t+k+C.slice(E);break;default:t=C+f+t+k}return s(t)}return g=void 0===g?6:/[gprs]/.test(v)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),k.toString=function(){return t+""},k}return{format:h,formatPrefix:function(t,e){var n=h(((t=Ji(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(na(e)/3))),i=Math.pow(10,-r),a=la[8+r/3];return function(t){return n(i*t)+a}}}}({thousands:",",grouping:[3],currency:["$",""]}),sa=oa.format,ca=oa.formatPrefix;class da extends Map{constructor(t,e=ya){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:e}}),null!=t)for(const[e,n]of t)this.set(e,n)}get(t){return super.get(pa(this,t))}has(t){return super.has(pa(this,t))}set(t,e){return super.set(function({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):(t.set(r,n),n)}(this,t),e)}delete(t){return super.delete(function({_intern:t,_key:e},n){const r=e(n);return t.has(r)&&(n=t.get(r),t.delete(r)),n}(this,t))}}function pa({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):n}function ya(t){return null!==t&&"object"==typeof t?t.valueOf():t}Set;const ga=Symbol("implicit");function ma(){var t=new da,e=[],n=[],r=ga;function i(i){let a=t.get(i);if(void 0===a){if(r!==ga)return r;t.set(i,a=e.push(i)-1)}return n[a%n.length]}return i.domain=function(n){if(!arguments.length)return e.slice();e=[],t=new da;for(const r of n)t.has(r)||t.set(r,e.push(r)-1);return i},i.range=function(t){return arguments.length?(n=Array.from(t),i):n.slice()},i.unknown=function(t){return arguments.length?(r=t,i):r},i.copy=function(){return ma(e,n).unknown(r)},Zi.apply(i,arguments),i}const va=1e3,ba=6e4,_a=36e5,xa=864e5,wa=6048e5,ka=31536e6;var Ta=new Date,Ea=new Date;function Ca(t,e,n,r){function i(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return i.floor=function(e){return t(e=new Date(+e)),e},i.ceil=function(n){return t(n=new Date(n-1)),e(n,1),t(n),n},i.round=function(t){var e=i(t),n=i.ceil(t);return t-e0))return s;do{s.push(o=new Date(+n)),e(n,a),t(n)}while(o=e)for(;t(e),!n(e);)e.setTime(e-1)}),(function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););}))},n&&(i.count=function(e,r){return Ta.setTime(+e),Ea.setTime(+r),t(Ta),t(Ea),Math.floor(n(Ta,Ea))},i.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?function(e){return r(e)%t==0}:function(e){return i.count(0,e)%t==0}):i:null}),i}var Sa=Ca((function(){}),(function(t,e){t.setTime(+t+e)}),(function(t,e){return e-t}));Sa.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?Ca((function(e){e.setTime(Math.floor(e/t)*t)}),(function(e,n){e.setTime(+e+n*t)}),(function(e,n){return(n-e)/t})):Sa:null};const Aa=Sa;Sa.range;var Ma=Ca((function(t){t.setTime(t-t.getMilliseconds())}),(function(t,e){t.setTime(+t+e*va)}),(function(t,e){return(e-t)/va}),(function(t){return t.getUTCSeconds()}));const Na=Ma;Ma.range;var Da=Ca((function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*va)}),(function(t,e){t.setTime(+t+e*ba)}),(function(t,e){return(e-t)/ba}),(function(t){return t.getMinutes()}));const Oa=Da;Da.range;var Ba=Ca((function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*va-t.getMinutes()*ba)}),(function(t,e){t.setTime(+t+e*_a)}),(function(t,e){return(e-t)/_a}),(function(t){return t.getHours()}));const La=Ba;Ba.range;var Ia=Ca((t=>t.setHours(0,0,0,0)),((t,e)=>t.setDate(t.getDate()+e)),((t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*ba)/xa),(t=>t.getDate()-1));const Ra=Ia;function Fa(t){return Ca((function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+7*e)}),(function(t,e){return(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*ba)/wa}))}Ia.range;var Pa=Fa(0),ja=Fa(1),Ya=Fa(2),za=Fa(3),Ua=Fa(4),qa=Fa(5),Ha=Fa(6),$a=(Pa.range,ja.range,Ya.range,za.range,Ua.range,qa.range,Ha.range,Ca((function(t){t.setDate(1),t.setHours(0,0,0,0)}),(function(t,e){t.setMonth(t.getMonth()+e)}),(function(t,e){return e.getMonth()-t.getMonth()+12*(e.getFullYear()-t.getFullYear())}),(function(t){return t.getMonth()})));const Wa=$a;$a.range;var Va=Ca((function(t){t.setMonth(0,1),t.setHours(0,0,0,0)}),(function(t,e){t.setFullYear(t.getFullYear()+e)}),(function(t,e){return e.getFullYear()-t.getFullYear()}),(function(t){return t.getFullYear()}));Va.every=function(t){return isFinite(t=Math.floor(t))&&t>0?Ca((function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)}),(function(e,n){e.setFullYear(e.getFullYear()+n*t)})):null};const Ga=Va;Va.range;var Xa=Ca((function(t){t.setUTCSeconds(0,0)}),(function(t,e){t.setTime(+t+e*ba)}),(function(t,e){return(e-t)/ba}),(function(t){return t.getUTCMinutes()}));const Za=Xa;Xa.range;var Qa=Ca((function(t){t.setUTCMinutes(0,0,0)}),(function(t,e){t.setTime(+t+e*_a)}),(function(t,e){return(e-t)/_a}),(function(t){return t.getUTCHours()}));const Ka=Qa;Qa.range;var Ja=Ca((function(t){t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+e)}),(function(t,e){return(e-t)/xa}),(function(t){return t.getUTCDate()-1}));const to=Ja;function eo(t){return Ca((function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+7*e)}),(function(t,e){return(e-t)/wa}))}Ja.range;var no=eo(0),ro=eo(1),io=eo(2),ao=eo(3),oo=eo(4),so=eo(5),co=eo(6),uo=(no.range,ro.range,io.range,ao.range,oo.range,so.range,co.range,Ca((function(t){t.setUTCDate(1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCMonth(t.getUTCMonth()+e)}),(function(t,e){return e.getUTCMonth()-t.getUTCMonth()+12*(e.getUTCFullYear()-t.getUTCFullYear())}),(function(t){return t.getUTCMonth()})));const lo=uo;uo.range;var ho=Ca((function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)}),(function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()}),(function(t){return t.getUTCFullYear()}));ho.every=function(t){return isFinite(t=Math.floor(t))&&t>0?Ca((function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)}),(function(e,n){e.setUTCFullYear(e.getUTCFullYear()+n*t)})):null};const fo=ho;function po(t,e,n,r,i,a){const o=[[Na,1,va],[Na,5,5e3],[Na,15,15e3],[Na,30,3e4],[a,1,ba],[a,5,3e5],[a,15,9e5],[a,30,18e5],[i,1,_a],[i,3,108e5],[i,6,216e5],[i,12,432e5],[r,1,xa],[r,2,1728e5],[n,1,wa],[e,1,2592e6],[e,3,7776e6],[t,1,ka]];function s(e,n,r){const i=Math.abs(n-e)/r,a=Wr((([,,t])=>t)).right(o,i);if(a===o.length)return t.every(Hr(e/ka,n/ka,r));if(0===a)return Aa.every(Math.max(Hr(e,n,r),1));const[s,c]=o[i/o[a-1][2][t.toLowerCase(),e])))}function Oo(t,e,n){var r=Eo.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function Bo(t,e,n){var r=Eo.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function Lo(t,e,n){var r=Eo.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function Io(t,e,n){var r=Eo.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function Ro(t,e,n){var r=Eo.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function Fo(t,e,n){var r=Eo.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function Po(t,e,n){var r=Eo.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function jo(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function Yo(t,e,n){var r=Eo.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function zo(t,e,n){var r=Eo.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function Uo(t,e,n){var r=Eo.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function qo(t,e,n){var r=Eo.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function Ho(t,e,n){var r=Eo.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function $o(t,e,n){var r=Eo.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function Wo(t,e,n){var r=Eo.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function Vo(t,e,n){var r=Eo.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function Go(t,e,n){var r=Eo.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function Xo(t,e,n){var r=Co.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function Zo(t,e,n){var r=Eo.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function Qo(t,e,n){var r=Eo.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function Ko(t,e){return Ao(t.getDate(),e,2)}function Jo(t,e){return Ao(t.getHours(),e,2)}function ts(t,e){return Ao(t.getHours()%12||12,e,2)}function es(t,e){return Ao(1+Ra.count(Ga(t),t),e,3)}function ns(t,e){return Ao(t.getMilliseconds(),e,3)}function rs(t,e){return ns(t,e)+"000"}function is(t,e){return Ao(t.getMonth()+1,e,2)}function as(t,e){return Ao(t.getMinutes(),e,2)}function os(t,e){return Ao(t.getSeconds(),e,2)}function ss(t){var e=t.getDay();return 0===e?7:e}function cs(t,e){return Ao(Pa.count(Ga(t)-1,t),e,2)}function us(t){var e=t.getDay();return e>=4||0===e?Ua(t):Ua.ceil(t)}function ls(t,e){return t=us(t),Ao(Ua.count(Ga(t),t)+(4===Ga(t).getDay()),e,2)}function hs(t){return t.getDay()}function fs(t,e){return Ao(ja.count(Ga(t)-1,t),e,2)}function ds(t,e){return Ao(t.getFullYear()%100,e,2)}function ps(t,e){return Ao((t=us(t)).getFullYear()%100,e,2)}function ys(t,e){return Ao(t.getFullYear()%1e4,e,4)}function gs(t,e){var n=t.getDay();return Ao((t=n>=4||0===n?Ua(t):Ua.ceil(t)).getFullYear()%1e4,e,4)}function ms(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+Ao(e/60|0,"0",2)+Ao(e%60,"0",2)}function vs(t,e){return Ao(t.getUTCDate(),e,2)}function bs(t,e){return Ao(t.getUTCHours(),e,2)}function _s(t,e){return Ao(t.getUTCHours()%12||12,e,2)}function xs(t,e){return Ao(1+to.count(fo(t),t),e,3)}function ws(t,e){return Ao(t.getUTCMilliseconds(),e,3)}function ks(t,e){return ws(t,e)+"000"}function Ts(t,e){return Ao(t.getUTCMonth()+1,e,2)}function Es(t,e){return Ao(t.getUTCMinutes(),e,2)}function Cs(t,e){return Ao(t.getUTCSeconds(),e,2)}function Ss(t){var e=t.getUTCDay();return 0===e?7:e}function As(t,e){return Ao(no.count(fo(t)-1,t),e,2)}function Ms(t){var e=t.getUTCDay();return e>=4||0===e?oo(t):oo.ceil(t)}function Ns(t,e){return t=Ms(t),Ao(oo.count(fo(t),t)+(4===fo(t).getUTCDay()),e,2)}function Ds(t){return t.getUTCDay()}function Os(t,e){return Ao(ro.count(fo(t)-1,t),e,2)}function Bs(t,e){return Ao(t.getUTCFullYear()%100,e,2)}function Ls(t,e){return Ao((t=Ms(t)).getUTCFullYear()%100,e,2)}function Is(t,e){return Ao(t.getUTCFullYear()%1e4,e,4)}function Rs(t,e){var n=t.getUTCDay();return Ao((t=n>=4||0===n?oo(t):oo.ceil(t)).getUTCFullYear()%1e4,e,4)}function Fs(){return"+0000"}function Ps(){return"%"}function js(t){return+t}function Ys(t){return Math.floor(+t/1e3)}function zs(t){return new Date(t)}function Us(t){return t instanceof Date?+t:+new Date(+t)}function qs(t,e,n,r,i,a,o,s,c,u){var l=Xi(),h=l.invert,f=l.domain,d=u(".%L"),p=u(":%S"),y=u("%I:%M"),g=u("%I %p"),m=u("%a %d"),v=u("%b %d"),b=u("%B"),_=u("%Y");function x(t){return(c(t)=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:js,s:Ys,S:os,u:ss,U:cs,V:ls,w:hs,W:fs,x:null,X:null,y:ds,Y:ys,Z:ms,"%":Ps},_={a:function(t){return o[t.getUTCDay()]},A:function(t){return a[t.getUTCDay()]},b:function(t){return c[t.getUTCMonth()]},B:function(t){return s[t.getUTCMonth()]},c:null,d:vs,e:vs,f:ks,g:Ls,G:Rs,H:bs,I:_s,j:xs,L:ws,m:Ts,M:Es,p:function(t){return i[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:js,s:Ys,S:Cs,u:Ss,U:As,V:Ns,w:Ds,W:Os,x:null,X:null,y:Bs,Y:Is,Z:Fs,"%":Ps},x={a:function(t,e,n){var r=d.exec(e.slice(n));return r?(t.w=p.get(r[0].toLowerCase()),n+r[0].length):-1},A:function(t,e,n){var r=h.exec(e.slice(n));return r?(t.w=f.get(r[0].toLowerCase()),n+r[0].length):-1},b:function(t,e,n){var r=m.exec(e.slice(n));return r?(t.m=v.get(r[0].toLowerCase()),n+r[0].length):-1},B:function(t,e,n){var r=y.exec(e.slice(n));return r?(t.m=g.get(r[0].toLowerCase()),n+r[0].length):-1},c:function(t,n,r){return T(t,e,n,r)},d:Uo,e:Uo,f:Go,g:Po,G:Fo,H:Ho,I:Ho,j:qo,L:Vo,m:zo,M:$o,p:function(t,e,n){var r=u.exec(e.slice(n));return r?(t.p=l.get(r[0].toLowerCase()),n+r[0].length):-1},q:Yo,Q:Zo,s:Qo,S:Wo,u:Bo,U:Lo,V:Io,w:Oo,W:Ro,x:function(t,e,r){return T(t,n,e,r)},X:function(t,e,n){return T(t,r,e,n)},y:Po,Y:Fo,Z:jo,"%":Xo};function w(t,e){return function(n){var r,i,a,o=[],s=-1,c=0,u=t.length;for(n instanceof Date||(n=new Date(+n));++s53)return null;"w"in a||(a.w=1),"Z"in a?(i=(r=_o(xo(a.y,0,1))).getUTCDay(),r=i>4||0===i?ro.ceil(r):ro(r),r=to.offset(r,7*(a.V-1)),a.y=r.getUTCFullYear(),a.m=r.getUTCMonth(),a.d=r.getUTCDate()+(a.w+6)%7):(i=(r=bo(xo(a.y,0,1))).getDay(),r=i>4||0===i?ja.ceil(r):ja(r),r=Ra.offset(r,7*(a.V-1)),a.y=r.getFullYear(),a.m=r.getMonth(),a.d=r.getDate()+(a.w+6)%7)}else("W"in a||"U"in a)&&("w"in a||(a.w="u"in a?a.u%7:"W"in a?1:0),i="Z"in a?_o(xo(a.y,0,1)).getUTCDay():bo(xo(a.y,0,1)).getDay(),a.m=0,a.d="W"in a?(a.w+6)%7+7*a.W-(i+5)%7:a.w+7*a.U-(i+6)%7);return"Z"in a?(a.H+=a.Z/100|0,a.M+=a.Z%100,_o(a)):bo(a)}}function T(t,e,n,r){for(var i,a,o=0,s=e.length,c=n.length;o=c)return-1;if(37===(i=e.charCodeAt(o++))){if(i=e.charAt(o++),!(a=x[i in To?e.charAt(o++):i])||(r=a(t,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}return b.x=w(n,b),b.X=w(r,b),b.c=w(e,b),_.x=w(n,_),_.X=w(r,_),_.c=w(e,_),{format:function(t){var e=w(t+="",b);return e.toString=function(){return t},e},parse:function(t){var e=k(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=w(t+="",_);return e.toString=function(){return t},e},utcParse:function(t){var e=k(t+="",!0);return e.toString=function(){return t},e}}}({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}),ko=wo.format,wo.parse,wo.utcFormat,wo.utcParse;var Qs=Array.prototype.find;function Ks(){return this.firstElementChild}var Js=Array.prototype.filter;function tc(){return Array.from(this.children)}function ec(t){return new Array(t.length)}function nc(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function rc(t){return function(){return t}}function ic(t,e,n,r,i,a){for(var o,s=0,c=e.length,u=a.length;se?1:t>=e?0:NaN}nc.prototype={constructor:nc,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var uc="http://www.w3.org/1999/xhtml";const lc={svg:"http://www.w3.org/2000/svg",xhtml:uc,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function hc(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),lc.hasOwnProperty(e)?{space:lc[e],local:t}:t}function fc(t){return function(){this.removeAttribute(t)}}function dc(t){return function(){this.removeAttributeNS(t.space,t.local)}}function pc(t,e){return function(){this.setAttribute(t,e)}}function yc(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function gc(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function mc(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function vc(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function bc(t){return function(){this.style.removeProperty(t)}}function _c(t,e,n){return function(){this.style.setProperty(t,e,n)}}function xc(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function wc(t,e){return t.style.getPropertyValue(e)||vc(t).getComputedStyle(t,null).getPropertyValue(e)}function kc(t){return function(){delete this[t]}}function Tc(t,e){return function(){this[t]=e}}function Ec(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function Cc(t){return t.trim().split(/^|\s+/)}function Sc(t){return t.classList||new Ac(t)}function Ac(t){this._node=t,this._names=Cc(t.getAttribute("class")||"")}function Mc(t,e){for(var n=Sc(t),r=-1,i=e.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}function Zc(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var eu=[null];function nu(t,e){this._groups=t,this._parents=e}function ru(){return new nu([[document.documentElement]],eu)}nu.prototype=ru.prototype={constructor:nu,select:function(t){"function"!=typeof t&&(t=$s(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i=x&&(x=_+1);!(b=g[x])&&++x=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=cc);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a1?this.each((null==e?bc:"function"==typeof e?xc:_c)(t,e,null==n?"":n)):wc(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?kc:"function"==typeof e?Ec:Tc)(t,e)):this.node()[t]},classed:function(t,e){var n=Cc(t+"");if(arguments.length<2){for(var r=Sc(this.node()),i=-1,a=n.length;++iuu)if(Math.abs(l*s-c*u)>uu&&i){var f=n-a,d=r-o,p=s*s+c*c,y=f*f+d*d,g=Math.sqrt(p),m=Math.sqrt(h),v=i*Math.tan((su-Math.acos((p+h-y)/(2*g*m)))/2),b=v/m,_=v/g;Math.abs(b-1)>uu&&(this._+="L"+(t+b*u)+","+(e+b*l)),this._+="A"+i+","+i+",0,0,"+ +(l*f>u*d)+","+(this._x1=t+_*s)+","+(this._y1=e+_*c)}else this._+="L"+(this._x1=t)+","+(this._y1=e)},arc:function(t,e,n,r,i,a){t=+t,e=+e,a=!!a;var o=(n=+n)*Math.cos(r),s=n*Math.sin(r),c=t+o,u=e+s,l=1^a,h=a?r-i:i-r;if(n<0)throw new Error("negative radius: "+n);null===this._x1?this._+="M"+c+","+u:(Math.abs(this._x1-c)>uu||Math.abs(this._y1-u)>uu)&&(this._+="L"+c+","+u),n&&(h<0&&(h=h%cu+cu),h>lu?this._+="A"+n+","+n+",0,1,"+l+","+(t-o)+","+(e-s)+"A"+n+","+n+",0,1,"+l+","+(this._x1=c)+","+(this._y1=u):h>uu&&(this._+="A"+n+","+n+",0,"+ +(h>=su)+","+l+","+(this._x1=t+n*Math.cos(i))+","+(this._y1=e+n*Math.sin(i))))},rect:function(t,e,n,r){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)+"h"+ +n+"v"+ +r+"h"+-n+"Z"},toString:function(){return this._}};const du=fu;function pu(t){return function(){return t}}var yu=Math.abs,gu=Math.atan2,mu=Math.cos,vu=Math.max,bu=Math.min,_u=Math.sin,xu=Math.sqrt,wu=1e-12,ku=Math.PI,Tu=ku/2,Eu=2*ku;function Cu(t){return t>1?0:t<-1?ku:Math.acos(t)}function Su(t){return t>=1?Tu:t<=-1?-Tu:Math.asin(t)}function Au(t){return t.innerRadius}function Mu(t){return t.outerRadius}function Nu(t){return t.startAngle}function Du(t){return t.endAngle}function Ou(t){return t&&t.padAngle}function Bu(t,e,n,r,i,a,o,s){var c=n-t,u=r-e,l=o-i,h=s-a,f=h*c-l*u;if(!(f*fN*N+D*D&&(T=C,E=S),{cx:T,cy:E,x01:-l,y01:-h,x11:T*(i/x-1),y11:E*(i/x-1)}}function Iu(){var t=Au,e=Mu,n=pu(0),r=null,i=Nu,a=Du,o=Ou,s=null;function c(){var c,u,l=+t.apply(this,arguments),h=+e.apply(this,arguments),f=i.apply(this,arguments)-Tu,d=a.apply(this,arguments)-Tu,p=yu(d-f),y=d>f;if(s||(s=c=du()),hwu)if(p>Eu-wu)s.moveTo(h*mu(f),h*_u(f)),s.arc(0,0,h,f,d,!y),l>wu&&(s.moveTo(l*mu(d),l*_u(d)),s.arc(0,0,l,d,f,y));else{var g,m,v=f,b=d,_=f,x=d,w=p,k=p,T=o.apply(this,arguments)/2,E=T>wu&&(r?+r.apply(this,arguments):xu(l*l+h*h)),C=bu(yu(h-l)/2,+n.apply(this,arguments)),S=C,A=C;if(E>wu){var M=Su(E/l*_u(T)),N=Su(E/h*_u(T));(w-=2*M)>wu?(_+=M*=y?1:-1,x-=M):(w=0,_=x=(f+d)/2),(k-=2*N)>wu?(v+=N*=y?1:-1,b-=N):(k=0,v=b=(f+d)/2)}var D=h*mu(v),O=h*_u(v),B=l*mu(x),L=l*_u(x);if(C>wu){var I,R=h*mu(b),F=h*_u(b),P=l*mu(_),j=l*_u(_);if(pwu?A>wu?(g=Lu(P,j,D,O,h,A,y),m=Lu(R,F,B,L,h,A,y),s.moveTo(g.cx+g.x01,g.cy+g.y01),Awu&&w>wu?S>wu?(g=Lu(B,L,R,F,l,-S,y),m=Lu(D,O,P,j,l,-S,y),s.lineTo(g.cx+g.x01,g.cy+g.y01),St?1:e>=t?0:NaN}function qu(t){return t}function Hu(){}function $u(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function Wu(t){this._context=t}function Vu(t){return new Wu(t)}function Gu(t){this._context=t}function Xu(t){this._context=t}function Zu(t){this._context=t}function Qu(t){return t<0?-1:1}function Ku(t,e,n){var r=t._x1-t._x0,i=e-t._x1,a=(t._y1-t._y0)/(r||i<0&&-0),o=(n-t._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(Qu(a)+Qu(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function Ju(t,e){var n=t._x1-t._x0;return n?(3*(t._y1-t._y0)/n-e)/2:e}function tl(t,e,n){var r=t._x0,i=t._y0,a=t._x1,o=t._y1,s=(a-r)/3;t._context.bezierCurveTo(r+s,i+s*e,a-s,o-s*n,a,o)}function el(t){this._context=t}function nl(t){this._context=new rl(t)}function rl(t){this._context=t}function il(t){this._context=t}function al(t){var e,n,r=t.length-1,i=new Array(r),a=new Array(r),o=new Array(r);for(i[0]=0,a[0]=2,o[0]=t[0]+2*t[1],e=1;e=0;--e)i[e]=(o[e]-i[e+1])/a[e];for(a[r-1]=(t[r]+i[r-1])/2,e=0;e=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}}this._x=t,this._y=e}};var sl=new Date,cl=new Date;function ul(t,e,n,r){function i(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return i.floor=function(e){return t(e=new Date(+e)),e},i.ceil=function(n){return t(n=new Date(n-1)),e(n,1),t(n),n},i.round=function(t){var e=i(t),n=i.ceil(t);return t-e0))return s;do{s.push(o=new Date(+n)),e(n,a),t(n)}while(o=e)for(;t(e),!n(e);)e.setTime(e-1)}),(function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););}))},n&&(i.count=function(e,r){return sl.setTime(+e),cl.setTime(+r),t(sl),t(cl),Math.floor(n(sl,cl))},i.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?function(e){return r(e)%t==0}:function(e){return i.count(0,e)%t==0}):i:null}),i}const ll=864e5,hl=6048e5;function fl(t){return ul((function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+7*e)}),(function(t,e){return(e-t)/hl}))}var dl=fl(0),pl=fl(1),yl=fl(2),gl=fl(3),ml=fl(4),vl=fl(5),bl=fl(6),_l=(dl.range,pl.range,yl.range,gl.range,ml.range,vl.range,bl.range,ul((function(t){t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+e)}),(function(t,e){return(e-t)/ll}),(function(t){return t.getUTCDate()-1})));const xl=_l;function wl(t){return ul((function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+7*e)}),(function(t,e){return(e-t-6e4*(e.getTimezoneOffset()-t.getTimezoneOffset()))/hl}))}_l.range;var kl=wl(0),Tl=wl(1),El=wl(2),Cl=wl(3),Sl=wl(4),Al=wl(5),Ml=wl(6),Nl=(kl.range,Tl.range,El.range,Cl.range,Sl.range,Al.range,Ml.range,ul((t=>t.setHours(0,0,0,0)),((t,e)=>t.setDate(t.getDate()+e)),((t,e)=>(e-t-6e4*(e.getTimezoneOffset()-t.getTimezoneOffset()))/ll),(t=>t.getDate()-1)));const Dl=Nl;Nl.range;var Ol=ul((function(t){t.setMonth(0,1),t.setHours(0,0,0,0)}),(function(t,e){t.setFullYear(t.getFullYear()+e)}),(function(t,e){return e.getFullYear()-t.getFullYear()}),(function(t){return t.getFullYear()}));Ol.every=function(t){return isFinite(t=Math.floor(t))&&t>0?ul((function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)}),(function(e,n){e.setFullYear(e.getFullYear()+n*t)})):null};const Bl=Ol;Ol.range;var Ll=ul((function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)}),(function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()}),(function(t){return t.getUTCFullYear()}));Ll.every=function(t){return isFinite(t=Math.floor(t))&&t>0?ul((function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)}),(function(e,n){e.setUTCFullYear(e.getUTCFullYear()+n*t)})):null};const Il=Ll;function Rl(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function Fl(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function Pl(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}Ll.range;var jl,Yl,zl={"-":"",_:" ",0:"0"},Ul=/^\s*\d+/,ql=/^%/,Hl=/[\\^$*+?|[\]().{}]/g;function $l(t,e,n){var r=t<0?"-":"",i=(r?-t:t)+"",a=i.length;return r+(a[t.toLowerCase(),e])))}function Xl(t,e,n){var r=Ul.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function Zl(t,e,n){var r=Ul.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function Ql(t,e,n){var r=Ul.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function Kl(t,e,n){var r=Ul.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function Jl(t,e,n){var r=Ul.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function th(t,e,n){var r=Ul.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function eh(t,e,n){var r=Ul.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function nh(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function rh(t,e,n){var r=Ul.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function ih(t,e,n){var r=Ul.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function ah(t,e,n){var r=Ul.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function oh(t,e,n){var r=Ul.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function sh(t,e,n){var r=Ul.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function ch(t,e,n){var r=Ul.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function uh(t,e,n){var r=Ul.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function lh(t,e,n){var r=Ul.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function hh(t,e,n){var r=Ul.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function fh(t,e,n){var r=ql.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function dh(t,e,n){var r=Ul.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function ph(t,e,n){var r=Ul.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function yh(t,e){return $l(t.getDate(),e,2)}function gh(t,e){return $l(t.getHours(),e,2)}function mh(t,e){return $l(t.getHours()%12||12,e,2)}function vh(t,e){return $l(1+Dl.count(Bl(t),t),e,3)}function bh(t,e){return $l(t.getMilliseconds(),e,3)}function _h(t,e){return bh(t,e)+"000"}function xh(t,e){return $l(t.getMonth()+1,e,2)}function wh(t,e){return $l(t.getMinutes(),e,2)}function kh(t,e){return $l(t.getSeconds(),e,2)}function Th(t){var e=t.getDay();return 0===e?7:e}function Eh(t,e){return $l(kl.count(Bl(t)-1,t),e,2)}function Ch(t){var e=t.getDay();return e>=4||0===e?Sl(t):Sl.ceil(t)}function Sh(t,e){return t=Ch(t),$l(Sl.count(Bl(t),t)+(4===Bl(t).getDay()),e,2)}function Ah(t){return t.getDay()}function Mh(t,e){return $l(Tl.count(Bl(t)-1,t),e,2)}function Nh(t,e){return $l(t.getFullYear()%100,e,2)}function Dh(t,e){return $l((t=Ch(t)).getFullYear()%100,e,2)}function Oh(t,e){return $l(t.getFullYear()%1e4,e,4)}function Bh(t,e){var n=t.getDay();return $l((t=n>=4||0===n?Sl(t):Sl.ceil(t)).getFullYear()%1e4,e,4)}function Lh(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+$l(e/60|0,"0",2)+$l(e%60,"0",2)}function Ih(t,e){return $l(t.getUTCDate(),e,2)}function Rh(t,e){return $l(t.getUTCHours(),e,2)}function Fh(t,e){return $l(t.getUTCHours()%12||12,e,2)}function Ph(t,e){return $l(1+xl.count(Il(t),t),e,3)}function jh(t,e){return $l(t.getUTCMilliseconds(),e,3)}function Yh(t,e){return jh(t,e)+"000"}function zh(t,e){return $l(t.getUTCMonth()+1,e,2)}function Uh(t,e){return $l(t.getUTCMinutes(),e,2)}function qh(t,e){return $l(t.getUTCSeconds(),e,2)}function Hh(t){var e=t.getUTCDay();return 0===e?7:e}function $h(t,e){return $l(dl.count(Il(t)-1,t),e,2)}function Wh(t){var e=t.getUTCDay();return e>=4||0===e?ml(t):ml.ceil(t)}function Vh(t,e){return t=Wh(t),$l(ml.count(Il(t),t)+(4===Il(t).getUTCDay()),e,2)}function Gh(t){return t.getUTCDay()}function Xh(t,e){return $l(pl.count(Il(t)-1,t),e,2)}function Zh(t,e){return $l(t.getUTCFullYear()%100,e,2)}function Qh(t,e){return $l((t=Wh(t)).getUTCFullYear()%100,e,2)}function Kh(t,e){return $l(t.getUTCFullYear()%1e4,e,4)}function Jh(t,e){var n=t.getUTCDay();return $l((t=n>=4||0===n?ml(t):ml.ceil(t)).getUTCFullYear()%1e4,e,4)}function tf(){return"+0000"}function ef(){return"%"}function nf(t){return+t}function rf(t){return Math.floor(+t/1e3)}jl=function(t){var e=t.dateTime,n=t.date,r=t.time,i=t.periods,a=t.days,o=t.shortDays,s=t.months,c=t.shortMonths,u=Vl(i),l=Gl(i),h=Vl(a),f=Gl(a),d=Vl(o),p=Gl(o),y=Vl(s),g=Gl(s),m=Vl(c),v=Gl(c),b={a:function(t){return o[t.getDay()]},A:function(t){return a[t.getDay()]},b:function(t){return c[t.getMonth()]},B:function(t){return s[t.getMonth()]},c:null,d:yh,e:yh,f:_h,g:Dh,G:Bh,H:gh,I:mh,j:vh,L:bh,m:xh,M:wh,p:function(t){return i[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:nf,s:rf,S:kh,u:Th,U:Eh,V:Sh,w:Ah,W:Mh,x:null,X:null,y:Nh,Y:Oh,Z:Lh,"%":ef},_={a:function(t){return o[t.getUTCDay()]},A:function(t){return a[t.getUTCDay()]},b:function(t){return c[t.getUTCMonth()]},B:function(t){return s[t.getUTCMonth()]},c:null,d:Ih,e:Ih,f:Yh,g:Qh,G:Jh,H:Rh,I:Fh,j:Ph,L:jh,m:zh,M:Uh,p:function(t){return i[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:nf,s:rf,S:qh,u:Hh,U:$h,V:Vh,w:Gh,W:Xh,x:null,X:null,y:Zh,Y:Kh,Z:tf,"%":ef},x={a:function(t,e,n){var r=d.exec(e.slice(n));return r?(t.w=p.get(r[0].toLowerCase()),n+r[0].length):-1},A:function(t,e,n){var r=h.exec(e.slice(n));return r?(t.w=f.get(r[0].toLowerCase()),n+r[0].length):-1},b:function(t,e,n){var r=m.exec(e.slice(n));return r?(t.m=v.get(r[0].toLowerCase()),n+r[0].length):-1},B:function(t,e,n){var r=y.exec(e.slice(n));return r?(t.m=g.get(r[0].toLowerCase()),n+r[0].length):-1},c:function(t,n,r){return T(t,e,n,r)},d:ah,e:ah,f:hh,g:eh,G:th,H:sh,I:sh,j:oh,L:lh,m:ih,M:ch,p:function(t,e,n){var r=u.exec(e.slice(n));return r?(t.p=l.get(r[0].toLowerCase()),n+r[0].length):-1},q:rh,Q:dh,s:ph,S:uh,u:Zl,U:Ql,V:Kl,w:Xl,W:Jl,x:function(t,e,r){return T(t,n,e,r)},X:function(t,e,n){return T(t,r,e,n)},y:eh,Y:th,Z:nh,"%":fh};function w(t,e){return function(n){var r,i,a,o=[],s=-1,c=0,u=t.length;for(n instanceof Date||(n=new Date(+n));++s53)return null;"w"in a||(a.w=1),"Z"in a?(i=(r=Fl(Pl(a.y,0,1))).getUTCDay(),r=i>4||0===i?pl.ceil(r):pl(r),r=xl.offset(r,7*(a.V-1)),a.y=r.getUTCFullYear(),a.m=r.getUTCMonth(),a.d=r.getUTCDate()+(a.w+6)%7):(i=(r=Rl(Pl(a.y,0,1))).getDay(),r=i>4||0===i?Tl.ceil(r):Tl(r),r=Dl.offset(r,7*(a.V-1)),a.y=r.getFullYear(),a.m=r.getMonth(),a.d=r.getDate()+(a.w+6)%7)}else("W"in a||"U"in a)&&("w"in a||(a.w="u"in a?a.u%7:"W"in a?1:0),i="Z"in a?Fl(Pl(a.y,0,1)).getUTCDay():Rl(Pl(a.y,0,1)).getDay(),a.m=0,a.d="W"in a?(a.w+6)%7+7*a.W-(i+5)%7:a.w+7*a.U-(i+6)%7);return"Z"in a?(a.H+=a.Z/100|0,a.M+=a.Z%100,Fl(a)):Rl(a)}}function T(t,e,n,r){for(var i,a,o=0,s=e.length,c=n.length;o=c)return-1;if(37===(i=e.charCodeAt(o++))){if(i=e.charAt(o++),!(a=x[i in zl?e.charAt(o++):i])||(r=a(t,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}return b.x=w(n,b),b.X=w(r,b),b.c=w(e,b),_.x=w(n,_),_.X=w(r,_),_.c=w(e,_),{format:function(t){var e=w(t+="",b);return e.toString=function(){return t},e},parse:function(t){var e=k(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=w(t+="",_);return e.toString=function(){return t},e},utcParse:function(t){var e=k(t+="",!0);return e.toString=function(){return t},e}}}({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}),Yl=jl.format,jl.parse,jl.utcFormat,jl.utcParse;var af={value:()=>{}};function of(){for(var t,e=0,n=arguments.length,r={};e=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function uf(t,e){for(var n,r=0,i=t.length;r0)for(var n,r,i=new Array(n),a=0;a=0&&e._call.call(void 0,t),e=e._next;--pf}()}finally{pf=0,function(){for(var t,e,n=ff,r=1/0;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:ff=e);df=t,Af(r)}(),vf=0}}function Sf(){var t=_f.now(),e=t-mf;e>1e3&&(bf-=e,mf=t)}function Af(t){pf||(yf&&(yf=clearTimeout(yf)),t-vf>24?(t<1/0&&(yf=setTimeout(Cf,t-_f.now()-bf)),gf&&(gf=clearInterval(gf))):(gf||(mf=_f.now(),gf=setInterval(Sf,1e3)),pf=1,xf(Cf)))}function Mf(t,e,n){var r=new Tf;return e=null==e?0:+e,r.restart((n=>{r.stop(),t(n+e)}),e,n),r}Tf.prototype=Ef.prototype={constructor:Tf,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?wf():+n)+(null==e?0:+e),this._next||df===this||(df?df._next=this:ff=this,df=this),this._call=t,this._time=n,Af()},stop:function(){this._call&&(this._call=null,this._time=1/0,Af())}};var Nf=hf("start","end","cancel","interrupt"),Df=[];function Of(t,e,n,r,i,a){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function a(c){var u,l,h,f;if(1!==n.state)return s();for(u in i)if((f=i[u]).name===n.name){if(3===f.state)return Mf(a);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u0)throw new Error("too late; already scheduled");return n}function Lf(t,e){var n=If(t,e);if(n.state>3)throw new Error("too late; already running");return n}function If(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function Rf(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var Ff,Pf=180/Math.PI,jf={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Yf(t,e,n,r,i,a){var o,s,c;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(c=t*n+e*r)&&(n-=t*c,r-=e*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),t*r180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(i(n)+"rotate(",null,r)-2,x:Rf(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(a.rotate,o.rotate,s,c),function(t,e,n,a){t!==e?a.push({i:n.push(i(n)+"skewX(",null,r)-2,x:Rf(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(a.skewX,o.skewX,s,c),function(t,e,n,r,a,o){if(t!==n||e!==r){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:Rf(t,n)},{i:s-2,x:Rf(e,r)})}else 1===n&&1===r||a.push(i(a)+"scale("+n+","+r+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,c),a=o=null,function(t){for(var e,n=-1,r=c.length;++n=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=ra&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,c.push({i:o,x:Rf(n,r)})),a=Qf.lastIndex;return a=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?Bf:Lf;return function(){var o=a(this,t),s=o.on;s!==r&&(i=(r=s).copy()).on(e,n),o.on=i}}var gd=iu.prototype.constructor;function md(t){return function(){this.style.removeProperty(t)}}function vd(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}function bd(t,e,n){var r,i;function a(){var a=e.apply(this,arguments);return a!==i&&(r=(i=a)&&vd(t,a,n)),r}return a._value=e,a}function _d(t){return function(e){this.textContent=t.call(this,e)}}function xd(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&_d(r)),e}return r._value=t,r}var wd=0;function kd(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function Td(){return++wd}var Ed=iu.prototype;kd.prototype=function(t){return iu().transition(t)}.prototype={constructor:kd,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=$s(t));for(var r=this._groups,i=r.length,a=new Array(i),o=0;o2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete a[i]):o=!1;o&&delete t.__transition}}(this,t)}))},iu.prototype.transition=function(t){var e,n;t instanceof kd?(e=t._id,t=t._name):(e=Td(),(n=Cd).time=wf(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,a=0;ae?1:t>=e?0:NaN}Yd.prototype={constructor:Yd,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var Vd="http://www.w3.org/1999/xhtml";const Gd={svg:"http://www.w3.org/2000/svg",xhtml:Vd,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Xd(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),Gd.hasOwnProperty(e)?{space:Gd[e],local:t}:t}function Zd(t){return function(){this.removeAttribute(t)}}function Qd(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Kd(t,e){return function(){this.setAttribute(t,e)}}function Jd(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function tp(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function ep(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function np(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function rp(t){return function(){this.style.removeProperty(t)}}function ip(t,e,n){return function(){this.style.setProperty(t,e,n)}}function ap(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function op(t,e){return t.style.getPropertyValue(e)||np(t).getComputedStyle(t,null).getPropertyValue(e)}function sp(t){return function(){delete this[t]}}function cp(t,e){return function(){this[t]=e}}function up(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function lp(t){return t.trim().split(/^|\s+/)}function hp(t){return t.classList||new fp(t)}function fp(t){this._node=t,this._names=lp(t.getAttribute("class")||"")}function dp(t,e){for(var n=hp(t),r=-1,i=e.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}function Lp(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var jp=[null];function Yp(t,e){this._groups=t,this._parents=e}function zp(){return new Yp([[document.documentElement]],jp)}Yp.prototype=zp.prototype={constructor:Yp,select:function(t){"function"!=typeof t&&(t=Md(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i=x&&(x=_+1);!(b=g[x])&&++x=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=Wd);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a1?this.each((null==e?rp:"function"==typeof e?ap:ip)(t,e,null==n?"":n)):op(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?sp:"function"==typeof e?up:cp)(t,e)):this.node()[t]},classed:function(t,e){var n=lp(t+"");if(arguments.length<2){for(var r=hp(this.node()),i=-1,a=n.length;++i{}};function Hp(){for(var t,e=0,n=arguments.length,r={};e=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function Vp(t,e){for(var n,r=0,i=t.length;r0)for(var n,r,i=new Array(n),a=0;a=0&&e._call.call(void 0,t),e=e._next;--Kp}()}finally{Kp=0,function(){for(var t,e,n=Zp,r=1/0;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Zp=e);Qp=t,fy(r)}(),ny=0}}function hy(){var t=iy.now(),e=t-ey;e>1e3&&(ry-=e,ey=t)}function fy(t){Kp||(Jp&&(Jp=clearTimeout(Jp)),t-ny>24?(t<1/0&&(Jp=setTimeout(ly,t-iy.now()-ry)),ty&&(ty=clearInterval(ty))):(ty||(ey=iy.now(),ty=setInterval(hy,1e3)),Kp=1,ay(ly)))}function dy(t,e,n){var r=new cy;return e=null==e?0:+e,r.restart((n=>{r.stop(),t(n+e)}),e,n),r}cy.prototype=uy.prototype={constructor:cy,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?oy():+n)+(null==e?0:+e),this._next||Qp===this||(Qp?Qp._next=this:Zp=this,Qp=this),this._call=t,this._time=n,fy()},stop:function(){this._call&&(this._call=null,this._time=1/0,fy())}};var py=Xp("start","end","cancel","interrupt"),yy=[];function gy(t,e,n,r,i,a){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function a(c){var u,l,h,f;if(1!==n.state)return s();for(u in i)if((f=i[u]).name===n.name){if(3===f.state)return dy(a);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u0)throw new Error("too late; already scheduled");return n}function vy(t,e){var n=by(t,e);if(n.state>3)throw new Error("too late; already running");return n}function by(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function _y(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var xy,wy=180/Math.PI,ky={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ty(t,e,n,r,i,a){var o,s,c;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(c=t*n+e*r)&&(n-=t*c,r-=e*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),t*r180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(i(n)+"rotate(",null,r)-2,x:_y(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(a.rotate,o.rotate,s,c),function(t,e,n,a){t!==e?a.push({i:n.push(i(n)+"skewX(",null,r)-2,x:_y(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(a.skewX,o.skewX,s,c),function(t,e,n,r,a,o){if(t!==n||e!==r){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:_y(t,n)},{i:s-2,x:_y(e,r)})}else 1===n&&1===r||a.push(i(a)+"scale("+n+","+r+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,c),a=o=null,function(t){for(var e,n=-1,r=c.length;++n>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Qy(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Qy(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Yy.exec(t))?new tg(e[1],e[2],e[3],1):(e=zy.exec(t))?new tg(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Uy.exec(t))?Qy(e[1],e[2],e[3],e[4]):(e=qy.exec(t))?Qy(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Hy.exec(t))?ig(e[1],e[2]/100,e[3]/100,1):(e=$y.exec(t))?ig(e[1],e[2]/100,e[3]/100,e[4]):Wy.hasOwnProperty(t)?Zy(Wy[t]):"transparent"===t?new tg(NaN,NaN,NaN,0):null}function Zy(t){return new tg(t>>16&255,t>>8&255,255&t,1)}function Qy(t,e,n,r){return r<=0&&(t=e=n=NaN),new tg(t,e,n,r)}function Ky(t){return t instanceof By||(t=Xy(t)),t?new tg((t=t.rgb()).r,t.g,t.b,t.opacity):new tg}function Jy(t,e,n,r){return 1===arguments.length?Ky(t):new tg(t,e,n,null==r?1:r)}function tg(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function eg(){return"#"+rg(this.r)+rg(this.g)+rg(this.b)}function ng(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function rg(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function ig(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new og(t,e,n,r)}function ag(t){if(t instanceof og)return new og(t.h,t.s,t.l,t.opacity);if(t instanceof By||(t=Xy(t)),!t)return new og;if(t instanceof og)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n0&&c<1?0:o,new og(o,s,c,t.opacity)}function og(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function sg(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function cg(t,e,n,r,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*n+(1+3*t+3*a-3*o)*r+o*i)/6}Dy(By,Xy,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:Vy,formatHex:Vy,formatHsl:function(){return ag(this).formatHsl()},formatRgb:Gy,toString:Gy}),Dy(tg,Jy,Oy(By,{brighter:function(t){return t=null==t?Iy:Math.pow(Iy,t),new tg(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?Ly:Math.pow(Ly,t),new tg(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:eg,formatHex:eg,formatRgb:ng,toString:ng})),Dy(og,(function(t,e,n,r){return 1===arguments.length?ag(t):new og(t,e,n,null==r?1:r)}),Oy(By,{brighter:function(t){return t=null==t?Iy:Math.pow(Iy,t),new og(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?Ly:Math.pow(Ly,t),new og(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new tg(sg(t>=240?t-240:t+120,i,r),sg(t,i,r),sg(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));const ug=t=>()=>t;function lg(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):ug(isNaN(t)?e:t)}const hg=function t(e){var n=function(t){return 1==(t=+t)?lg:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):ug(isNaN(e)?n:e)}}(e);function r(t,e){var r=n((t=Jy(t)).r,(e=Jy(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=lg(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1);function fg(t){return function(e){var n,r,i=e.length,a=new Array(i),o=new Array(i),s=new Array(i);for(n=0;n=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=ra&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,c.push({i:o,x:_y(n,r)})),a=pg.lastIndex;return a=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?my:vy;return function(){var o=a(this,t),s=o.on;s!==r&&(i=(r=s).copy()).on(e,n),o.on=i}}var Bg=Up.prototype.constructor;function Lg(t){return function(){this.style.removeProperty(t)}}function Ig(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}function Rg(t,e,n){var r,i;function a(){var a=e.apply(this,arguments);return a!==i&&(r=(i=a)&&Ig(t,a,n)),r}return a._value=e,a}function Fg(t){return function(e){this.textContent=t.call(this,e)}}function Pg(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&Fg(r)),e}return r._value=t,r}var jg=0;function Yg(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function zg(){return++jg}var Ug=Up.prototype;Yg.prototype=function(t){return Up().transition(t)}.prototype={constructor:Yg,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=Md(t));for(var r=this._groups,i=r.length,a=new Array(i),o=0;o2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete a[i]):o=!1;o&&delete t.__transition}}(this,t)}))},Up.prototype.transition=function(t){var e,n;t instanceof Yg?(e=t._id,t=t._name):(e=zg(),(n=qg).time=oy(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,a=0;a0?tm(fm,--lm):0,cm--,10===hm&&(cm=1,sm--),hm}function ym(){return hm=lm2||bm(hm)>3?"":" "}function wm(t,e){for(;--e&&ym()&&!(hm<48||hm>102||hm>57&&hm<65||hm>70&&hm<97););return vm(t,mm()+(e<6&&32==gm()&&32==ym()))}function km(t){for(;ym();)switch(hm){case t:return lm;case 34:case 39:34!==t&&39!==t&&km(hm);break;case 40:41===t&&km(t);break;case 92:ym()}return lm}function Tm(t,e){for(;ym()&&t+hm!==57&&(t+hm!==84||47!==gm()););return"/*"+vm(e,lm-1)+"*"+Zg(47===t?t:ym())}function Em(t){for(;!bm(gm());)ym();return vm(t,lm)}function Cm(t){return function(t){return fm="",t}(Sm("",null,null,null,[""],t=function(t){return sm=cm=1,um=nm(fm=t),lm=0,[]}(t),0,[0],t))}function Sm(t,e,n,r,i,a,o,s,c){for(var u=0,l=0,h=o,f=0,d=0,p=0,y=1,g=1,m=1,v=0,b="",_=i,x=a,w=r,k=b;g;)switch(p=v,v=ym()){case 40:if(108!=p&&58==k.charCodeAt(h-1)){-1!=Jg(k+=Kg(_m(v),"&","&\f"),"&\f")&&(m=-1);break}case 34:case 39:case 91:k+=_m(v);break;case 9:case 10:case 13:case 32:k+=xm(p);break;case 92:k+=wm(mm()-1,7);continue;case 47:switch(gm()){case 42:case 47:im(Mm(Tm(ym(),mm()),e,n),c);break;default:k+="/"}break;case 123*y:s[u++]=nm(k)*m;case 125*y:case 59:case 0:switch(v){case 0:case 125:g=0;case 59+l:d>0&&nm(k)-h&&im(d>32?Nm(k+";",r,n,h-1):Nm(Kg(k," ","")+";",r,n,h-2),c);break;case 59:k+=";";default:if(im(w=Am(k,e,n,u,l,i,s,b,_=[],x=[],h),a),123===v)if(0===l)Sm(k,e,w,w,_,a,h,s,x);else switch(f){case 100:case 109:case 115:Sm(t,w,w,r&&im(Am(t,w,w,0,0,i,s,b,i,_=[],h),x),i,x,h,s,r?_:x);break;default:Sm(k,w,w,w,[""],x,0,s,x)}}u=l=d=0,y=m=1,b=k="",h=o;break;case 58:h=1+nm(k),d=p;default:if(y<1)if(123==v)--y;else if(125==v&&0==y++&&125==pm())continue;switch(k+=Zg(v),v*y){case 38:m=l>0?1:(k+="\f",-1);break;case 44:s[u++]=(nm(k)-1)*m,m=1;break;case 64:45===gm()&&(k+=_m(ym())),f=gm(),l=h=nm(b=k+=Em(mm())),v++;break;case 45:45===p&&2==nm(k)&&(y=0)}}return a}function Am(t,e,n,r,i,a,o,s,c,u,l){for(var h=i-1,f=0===i?a:[""],d=rm(f),p=0,y=0,g=0;p0?f[m]+" "+v:Kg(v,/&\f/g,f[m])))&&(c[g++]=b);return dm(t,e,n,0===i?Vg:s,c,u,l)}function Mm(t,e,n){return dm(t,e,n,Wg,Zg(hm),em(t,2,-2),0)}function Nm(t,e,n,r){return dm(t,e,n,Gg,em(t,0,r),em(t,r+1,-1),r)}const Dm="8.13.10";var Om=n(9609),Bm=n(7856),Lm=n.n(Bm),Im=function(t){var e=t.replace(/\\u[\dA-F]{4}/gi,(function(t){return String.fromCharCode(parseInt(t.replace(/\\u/g,""),16))}));return e=(e=(e=e.replace(/\\x([0-9a-f]{2})/gi,(function(t,e){return String.fromCharCode(parseInt(e,16))}))).replace(/\\[\d\d\d]{3}/gi,(function(t){return String.fromCharCode(parseInt(t.replace(/\\/g,""),8))}))).replace(/\\[\d\d\d]{2}/gi,(function(t){return String.fromCharCode(parseInt(t.replace(/\\/g,""),8))}))},Rm=function(t){for(var e="",n=0;n>=0;){if(!((n=t.indexOf("=0)){e+=t,n=-1;break}e+=t.substr(0,n),(n=(t=t.substr(n+1)).indexOf("<\/script>"))>=0&&(n+=9,t=t.substr(n))}var r=Im(e);return(r=(r=(r=r.replace(/script>/gi,"#")).replace(/javascript:/gi,"#")).replace(/onerror=/gi,"onerror:")).replace(/