CSSE4630 Rust-Inspired Analyses

【图论 BFS染色 并集查找 】P3663 [USACO17FEB] Why Did the Cow Cross the Road III S|普及+ Why Did the Cow Cross the Road III S ## 题目描述 奶牛为什么要过马路?其中一个原因是 Farmer John 的农场有很多道路,使得他的奶牛在四处走动时不可避免地要穿过许多道路。 FJ 的农场被安排成一个 $N \times N$ 的方形网格田地($2 \leq N \leq 100$),某些相邻的田地(例如南北向或东西向)被道路分隔,整个网格的外部有一圈高高的围栏,防止奶牛离开农场。奶牛可以从任何田地自由移动到相邻的田地(北、东、南或西),尽管它们除非绝对必要 阅读详情

CSSE4630 Assignment One: Rust-Inspired Analyses

2024 version 1.0

1 Introduction

This assignment is focused on several kinds of analysis inspired by the Rust programming language. Rust is a strongly typed language that uses a sophisticated type system to prevent many kinds of programming errors, including memory safety errors. It provides a powerful ownership system that allows the programmer to control the lifetimes of objects and ensure that they are not used after they have been deallocated. This assignment will focus on two kinds of analysis that are used in Rust.

The goal of the assignment is to give you experience with implementing static analyses, and at the same time develop a better understanding of the techniques that Rust uses to guarantee type safety and memory safety.

You will first implement type checking for TIP, so that we can distinguish pointers from inte-gers.

Then you will design a new analysis for TIP that corresponds to the ownership checker of Rust. Optionally, you can extend this analysis to be interprocedural.

This assignment is worth 20% of your final mark for this course. It is due on Friday 3-Oct-2024 before 4:00pm. You can submit your solution multiple times to Gradescope before this deadline, to check that various aspects are working correctly.

2 School Policy on Student Misconduct

This assignment is to be completed individually. You are required to read and understand the School Statement on Misconduct, available on the School’s website at: https://eecs.uq.edu.au/current-students/guidelines-and-policies-students/student-conduct

You may appropriately use AI as a programming aid while completing these assessment tasks, but you must clearly reference any AI-generated code (following the usual UQ AI guidelines: https://guides.library.uq.edu.au/referencing/generative-ai-tools-assignments), just as you should acknowledge any code fragments adapted from other internet sources. Include these acknowledgements as comments in your Scala source code. A failure to reference genera-tive AI or machine translation (MT) use may constitute student misconduct under the Student Code of Conduct.

3 Implementing Type Checking [40%]

The TIP system does not fully implement static type checking yet. To see this, run the following command and read the exception it generates:

tip -types examples/ptr7.tip

Implement the missing cases in the visit method in TypeAnalysis.scala. See Section 3.2 (Type Constraints) of the textbook for the rules you should implement.

Hints:

1. The solver is already created for you, so you can just call its unify method.

2. The address-of constructor in the textbook (&X) corresponds to PointerRef( ) in the Scala code.

3. To allocate a fresh variable (called α in the textbook) use the FreshVariable() function.

4. It is important that each occurrence of the same TIP variable must be mapped to the same type variable. You could implement this yourself, by defining a mapping from identifiers to type variables, but this gets quite tricky, because you really need to take into account the scope of each variable. For example, two different functions might both use a variable with the same name, but we should really treat them as separate variables, possibly with different types! Fortunately, TIP makes our task easier by providing the declData(id) method, which maps each variable to its correct declaration. So rather than implementing your own mapping, you can use this method to get a common handle (the declaration object) for all occurrences of a variable in that scope, then map that declaration object to a unique type variable for all occurrences of the identifier.

3.1 Checking your results

Use your type checking algorithm to analyse the tests/main1.tip program. You can download several example test files like this from Blackboard. This example checks that you are unifying type variables correctly, and also that your type checking algorithm knows that the main method is special, because it always has integer inputs and outputs.

You should see standard output being printed that includes the following results:

[info] Inferred types:

[main(a[2 : 6], b[2 : 9])... : 1 : 1 K = (int,int) -> int

[a[2 : 6] K = int [b[2 : 9] K = int [c[3 : 9] K = int

You can submit your solution (multiple times) to Gradescope to get feedback from several tests like this. After the deadline, your final typechecker will be tested using additional test programs and marked for correctness and elegance.

4 Implementing a Simple Ownership Algorithm [40%]

Next we want to implement a simple ‘ownership’ algorithm for heap variables, to track a unique owner for each heap-allocated memory location. When this owner goes out of scope, we can deallocate that heap variable. Variables that store non-heap values, such as integers, we can ignore.

For our analysis, we will map each variable to an ownership status, which will be one of the following three options:

• HeapOwner: the variable points to a heap-allocated value and is the unique owner of that value.

• HeapNotOwner: the variable points to a heap-allocated value but is NOT the owner of that value. It is illegal to read the heap value via this variable.

• NonHeap: the variable does not point to the heap. For example the variable contains integer values.

Our analysis will be a forward analysis. Initially, we will start with a simple intraprocedural analysis and will restrict our input language so that pointers only point directly to heap allocated values, not to local variables, and not to other pointers in the heap. In other words, you can assume that:

1. the address-of (&x) operator will not appear in our input programs.

2. the value stored inside a heap allocated memory location will always be an integer.

The rules for ownership analysis of a CFG node v are as follows:

[vars v1, v2, . . .] = JOIN(v)[v1 → ⊥, v2 → ⊥, . . .]

               [x = y] = JOIN(v)[x → eval(y, JOIN(v)), y 7→ yo], where

                      yo = let o = eval(y, JOIN(v)) in (if (o = HeapOwner) o else HeapNotOwner)

               [x = E] = JOIN(v)[x → eval(y, JOIN(v))], if E is not an identifier

For the eval function, alloc e should evaluate to HeapOwner obviously. All non-pointer values such as integers will evaluate to NonHeap. So all binary operators and constants will evaluate to NonHeap. The dereference operator &x must check that x is a HeapOwner, and if so, return NonHeap (because the dereferenced result should be an integer), otherwise give either an error or a warning:

• Reason.OwnershipError if x is definitely not a HeapOwner.

   Error message should be: illegal dereference when not owner: x.

• Reason.OwnershipWarning if x might not be a HeapOwner.

   Warning message should be: dereference when may not be owner: x.

Hints:

1. A good strategy when developing a new feature in an unfamiliar system is to start by copying and modifying one of the existing features. In this case, you might start off by copying SimpleSignAnalysis.scala and renaming everything to OwnershipAnalysis. For the simplest approach, I suggest starting from SimpleSignAnalysis, because it also uses a nice small flat lattice, is a forward analysis, and is written in an easy-to-understand self-contained style. (rather than using inheritance to reuse worklist solvers, etc. which is a better approach in the long term, but requires more knowledge of all the various traits and classes available in TIP). However, if you plan to do the advanced interprocedural analysis (Section 5) part of this assignment, you might want to start by copying the more complex SignAnalysis.scala, because it illustrates how to support the interprocedural analysis that you will need for that part of the assignment.

2. To integrate your new analysis into the tip command line, you will need to define a new command line flag (-ownership) and implement this in at least Tip.scala and the master controller superclass FlowSensitiveAnalysis. Again, follow a similar example: SimpleSignAnalysis or SignAnalysis.

4.1 Reporting Ownership Errors and Warnings

Generate an error whenever the program tries to reference a heap-allocated value that is defi-nitely not owned by the current variable. Generate a warning whenever a variable is derefer-enced that may not be a HeapOwner (e.g. Top). For the automated testing and marking of your solution you must report these errors and warnings in exactly the way described in this section.

You must use the supplied MessageHandler class to record and print all your error and warning message. Download this Scala class from Blackboard and put it into the src/tip/util folder of your TIP project. Create a new instance of the MessageHandler class as a field of your analysis class.

Then in your analysis code call the message(Level, Location, Msg) method of your message handler whenever you want to record an error or warning. The Level parameter should be OwnershipError or OwnershipWarning, or None if there is no error at that location. The Location parameter is the location in the program where the error or warning occurs (you can get this from the loc field of the statement or expression you are analysing), and the Msg parameter should be a string that describes the error or warning.

You should also clear any previous error messages for the same location before adding a new one, so that you do not get multiple error messages for the same location. For example, you should have code like this in your analysis for each of your ownership error or warning checks:

if (some condition ) {

// no error here, so clear any previous error message for this location

msgs.message(msgs.Reason.None, loc)

. . .

} else {

val reason = msgs.Reason.OwnershipError

msgs.message(reason, loc, s"illegal dereference when not owner: $expr")

. . .

}

5 Advanced Ownership - Interprocedural [20%]

This is a more difficult part of the assignment that you should attempt only after completing all previous parts. The goal is to improve your ownership checker so that it can also analyse TIP programs that use function calls.

Follow the general interprocedural rules given in Section 8.1 of the textbook. You should im-plement at least the iwlr version of your interprocedural analysis, so that when you run:

• tip -ownership tests/ownership1.tip it runs the intraprocedural version of your anal-ysis.

• tip -ownership iwlr tests/ownership1.tip it runs the interprocedural version of your analysis.

In practice, you should include the following options in your TIP command line to ensure that programs are normalised into a standard form.

• -normalizereturns normalize return statements

• -normalizecalls normalize function calls

• -normalizepointers normalize pointer usages

We are not concerned with the full Rust ownership system, so you can ignore the borrow checker and the lifetime annotations. In other words, you can still assume that the address-of (&x) operator will not appear in our input programs and that heap locations will only store integers.

Hints:

1. If you want to implement the interprocedural analysis, I recommend you use the SignAnalysis class as a starting point, because it already has the necessary infrastructure for interpro-cedural analysis, such as using an interprocedural CFG.

2. One of the challenges with interprocedural analysis is finding the connections between caller and callee functions. Fortunately, the InterproceduralProgramCfg pre-calculates these connections for you. A CfgFunEntryNode node has a callers field that gives you the set of all functions that call this function and a CfgCallNode has a callees field that gives the set of possible functions being called. Also, a CfgAfterCallNode node has a calleeExits field that gives you all the function exit nodes that might be returning to that after-call node. So you can use these fields to find the connections between caller and callee functions.

6 Submission

Submit your assignment via Gradescope, as a single zip file containing your whole tip directory (with subdirectories called src, tests, out etc.). The src subdirectory will include your mod-ified Scala source files that implement your pointer analysis algorithms. The out subdirectory should include your output files for each *.tip test file in the tests directory.

You can submit multiple times before the deadline to check that your submission has the correct structure and that the provided tests work correctly. It is your last submission before the deadline that will count.

After the deadline, your final submission will be tested using additional test programs and marked for correctness and elegance.

OFDM基本原理 OFDM基础介绍,包括OFDM的核心思想,数学推导了OFDM信号的调制解调过程。 阅读详情

相关推荐

【Qualcomm高通音频】音效调试_录音文件播放有杂音,如何定位原因?

一、录音播放数据处理过程介绍 (1)TX方向 麦克风(硅麦克风或者主机体麦克风)采集模拟音频信号,经过内部CODEC芯片中的adc转换为数字信号,在经过高通音频DSP处理音效后编码为wav/aac/amr/mp3等格式文件。 (2)RX方向 音频文件经过解码、重采样还原为pcm数据,经过DSP处理音效后送到内部CODEC,然后经过DAC转换为模拟信号,送到喇叭。 二、分析步骤 1...

crow_ch的博客 5976

P3612 [USACO17JAN] Secret Cow Code S

给定一个字符串 s,令 F(s) 为 s 后接 s 向右“旋转”一个字符的结果(在右旋转中,s 的最后一个字符旋转并成为新的第一个字符)。请注意,N 可能太大,无法放入标准的 32 位整数中,因此你可能需要使用 64 位整数类型(例如,C/C++ 中的 "long long")。奶牛们正在实验秘密代码,并设计了一种方法用于生成无限长度的字符串,作为他们代码的一部分。请输出从初始字符串构建的无限代码字符串的第 N 个字符。给定初始字符串和一个索引 N,请帮助奶牛计算无限代码字符串中第 N 个位置的字符。

Ct314的博客 8763

软件工程案例教程·韩万江【课后习题】

!!!!

weixin_57858263的博客 6422

[USACO17JAN]Secret Cow Code秘密奶牛码(洛谷 P3612)

[USACO17JAN]Secret Cow Code秘密奶牛码 题目描述 The cows are experimenting with secret codes, and have devised a method for creating an infinite-length string to be used as part of one of their codes. Given a s...

不知所云的博客 3194

5分钟搞定:用Ollama在MacBook上本地运行Qwen3大模型(附避坑指南)

本文详细介绍了如何在MacBook上使用Ollama快速部署和运行Qwen3大模型,包括安装步骤、性能优化技巧及常见问题解决方案。Ollama作为一款轻量级工具,特别适合M系列芯片的Mac用户,支持多种量化版本,显著降低资源消耗,提升推理速度。

sql99的博客 825

【移远EG800K-CN】从AT指令到MQTT实战:4G模块云端通信全解析

本文详细解析移远EG800K-CN 4G模块的AT指令应用与MQTT云端通信实战。从硬件连接到网络配置,再到MQTT协议的数据上报与命令接收,提供了完整的物联网通信解决方案,帮助开发者快速实现设备与云端的稳定数据交互。

o1p2q3r的博客 561

[USACO]秘密奶牛码

奶牛正在试验秘密代码,并设计了一种方法来创建一个无限长的字符串作为其代码的一部分使用。 给定一个字符串,让后面的字符旋转一次(每一次正确的旋转,最后一个字符都会成为新的第一个字符)。也就是说,给定一个初始字符串,之后的每一步都会增加当前字符串的长度。 给定初始字符串和索引,请帮助奶牛计算无限字符串中位置N的字符。 COW -> COWWCO -> COWWCOOC...

denghuan6474的博客 736

FLUKA软件在Ubuntu的安装指南(亲测有效)

FLUKA其强大的蒙特卡洛模拟能力使得用户能够模拟复杂的辐射相互作用过程

chencheng1127的博客 2889

洛谷-P3612 [USACO17JAN]Secret Cow Code S

题目描述 The cows are experimenting with secret codes, and have devised a method for creating an infinite-length string to be used as part of one of their codes. Given a stringss, letF(s)F(s)bessfollowed byss"rotated" one character to the right (in a ...

weixin_43098069的博客 2050

英语语法-句法

摘要:本文系统梳理了英语句法知识,重点解析了五种基本句型及其扩展结构。内容包括句子类型(陈述句、疑问句、祈使句、感叹句)、复合句构成(从句分类与连词使用)、特殊句型(倒装、强调、引语转换)等。特别强调句子成分分析技巧,指出每种句子成分可由不同词法单元充当,需掌握成分识别与划分方法。文章还提供了往期语法系列链接,形成完整的英语语法学习体系,帮助读者建立从词法到句法的系统认知框架。

STCNXPARM的博客 8834

基于STM32L4XX、HAL库的ICP-10111压力传感器驱动程序设计

define ICP10111_CMD_MEAS_ULN 0x7866 // 超低噪声模式。#define ICP10111_CMD_MEAS_LP 0x609C // 低功耗模式。#define ICP10111_CMD_MEAS_LN 0x70DF // 低噪声模式。#define ICP10111_CMD_MEAS_N 0x6825 // 正常模式。ICP10111_MODE_LN, // 低噪声。// 等待测量完成(根据模式不同等待时间不同)

zhusl6688的博客 417

CSSE4630 One: Rust-Inspired Analyses 2024C/C++

v1 , v2 , . . .I = JOIN(v)[v1 \→ 丄, v2 \→ 丄, . . .]

stratch5的博客 665

使用C# HslCommunication库实现三菱PLC通信(含完整代码示例)

在工业自动化开发中,上位机与PLC的通信是关键环节。HslCommunication库是一个开源的.NET工业通信库,支持三菱、西门子、欧姆龙等多个品牌PLC的通信协议。本文将演示如何通过库实现C#程序与三菱PLC的通信,并提供完整的代码示例。

StevenChen的博客 2294

【Linux系统编程】(十七)揭秘 Linux 进程创建与终止:从 fork 到 exit 的底层逻辑全解析

本文深入解析Linux进程创建与终止的底层原理。进程创建主要通过fork函数实现,其特点是"一次调用,两次返回",父进程获取子进程PID,子进程返回0。Linux采用写时拷贝(COW)技术优化fork性能,避免不必要的内存复制。进程终止分为正常终止(return/exit/_exit)和异常终止(信号触发),每种方式都有不同的资源清理机制。退出码(0-255)用于反馈进程执行状态,0表示成功,非0表示失败。

2301_79248256的博客 5505

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

【C++开发者必看】:2025年AI编码助手如何应对GCC、Clang、MSVC兼容性地狱

解决AI编程工具在C++多编译器环境下的兼容难题。通过2025全球C++及系统软件技术大会最新分享,解析AI编码助手如何应对GCC、Clang、MSVC的版本差异与标准支持不一,提升开发效率。涵盖跨平台构建、语法树适配与智能提示优化,值得收藏。

InstrIsle的博客 3930

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

CH#17C 舞动的夜晚(最大流+强连通分量)

题意:L公司和H公司举办了一次联谊晚会。晚会上,L公司的N位员工和H公司的M位员工打算进行一场交际舞。在这些领导中,一些L公司的员工和H公司的员工之间是互相认识的,这样的认识关系一共有T对。舞会上,每位员工会尝试选择一名Ta认识的对方公司的员工作为舞伴,并且每位员工至多跳一支舞。完成的交际舞的数量越多,晚会的气氛就越热烈。顾及到晚会的气氛,员工们希望知道,哪些员工之间如果进行了交际舞,就会使整场晚...

常胜将军的博客 3万+

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

17. C语言 -- 指针和数组的关系

本博客主要内容为 “小甲鱼” 视频课程《带你学C带你飞》【第一季】 学习笔记,文章的主题内容均来自该课程,在这里仅作学习交流。在文章中可能出现一些错误或者不准确的地方,如发现请积极指出,十分感谢。 也欢迎大家一起讨论交流,如果你觉得这篇文章对你有所帮助,记得评论、点赞哦 ~(。・∀・)ノ゙ 1. 指针和数组的关系   指针和数组之间的关系虽然十分微妙,但是不可以认为指针就是数组,因为数组名是数...

dugudaibo的博客 12万+

[USACO17FEB]Why Did the Cow Cross the Road I S

题目描述 Farmer John's cows are trying to learn to cross the road effectively. Remembering the old "why did the chicken cross the road?" joke, they figure the chickens must be experts on crossing th...

aoanping0730的博客 1144

17.C 指针

C指针 学习 C 语言的指针既简单又有趣。通过指针,可以简化一些 C 编程任务的执行,还有一些任务,如动态内存分配,没有指针是无法执行的。所以,想要成为一名优秀的 C 程序员,学习指针是很有必要的。 正如您所知道的,每一个变量都有一个内存位置,每一个内存位置都定义了可使用连字号(&am...

chengsi7614的博客 22万+

ACM题库以及培养策略

ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge。除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库。 USACO http://ace.delos.com/usacogate 美国著名在线题库,专门为信息学竞赛选手准备 TJU http://acm.tongji.edu.cn/ 同济大学在线题...

feiliboos 1090

【c/c++】从C到C++快速入门(会c语言想学c++看这篇文章就够了)

从事嵌入式多年,一直和mcu打交道,只用到c语言,后来为了学习QT。就得学习c++,市面上很多教程都是从基础开始教。明显不适合我,经过网上大量查找和总结,终于整理成一篇以从事c语言工作者的角度,快速跨入c++工作者的笔记。适合于c语言基础扎实的人学习,可以快速掌握c++。

莲花码农 3404

C++ string的COW和SSO策略

现代化的编译器大多数都是实现的SSO策略,我们在编码过程中不用太关注string的实现细节,但对于COW和SSO的基本概念要有基础的了解,更进一步的了解COW和SSO策略可以查看对应编译器提供的源码。

小小的进步 3080

C语言基础语法复习05-c17详解

C17(C18)是C11标准的"bugfix发布",没有新功能。

weixin_43172531的博客 3万+

[luogu p3612] [USACO17JAN]Secret Cow Code S

传送门 [USACO17JAN]Secret Cow Code S 题目描述 The cows are experimenting with secret codes, and have devised a method for creating an infinite-length string to be used as part of one of their codes. Giv...

crab_xbc的博客 402

xv6-2025-实验5-copy-on-write

为了能够检测何时需要真正的“复制”,内核将父子进程的所有用户内存页(原本可写的页)在页表中的条目(PTE)都标记为 只读。之后,当父进程或子进程尝试向这些共享的页面写入数据时,由于页面被标记为只读,CPU 会产生一个页错误。本实验最核心的部分在于计数,因为一个物理页现在可能被多个进程共享,你不能在第一个进程退出时就释放它,否则其他进程会访问到已释放的内存,导致崩溃。这就意味着,父进程并没有执行任何操作,却会发现自己的内存数据被子进程(通过内核)篡改了,从而严重破坏了进程间的内存隔离性。

qq_52392922的博客 1358

P3610 [USACO17JAN]Cow Navigation G

这个题能蓝题,读题的难度有很大的功劳,看了很多题解或者是讨论区的翻译,大概直到这个题说的是啥,就是一个人在起点要去终点,求最短的操作序列的长度,就是按照这个操作序列走,不管一开始人是面向上边,还是面向右边,都能走到终点,如果有的操作致使途中走到障碍上面或者出界,那么这个操作可以不做,就是人维持操作之前的状态,求这样一个操作序列的最短长度,这个题简直和天津OI2008那道题一模一样,就是题面难读,外加其中一个走到终点,那么它就可以不用动了,所以还是要稍微难一点。

m0_73035684的博客 313
上一篇: Computer Science A67
下一篇: FINANCE-304 Financial Modeling
vx___codinghelp
博客等级 码龄2年 778粉丝 101原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值